mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
22 lines
710 B
Python
22 lines
710 B
Python
from flask import current_app, render_template
|
|
from flask_mail import Message
|
|
from threading import Thread
|
|
from . import mail
|
|
|
|
|
|
def send_async_email(app, msg):
|
|
with app.app_context():
|
|
mail.send(msg)
|
|
|
|
|
|
def send_email(to, subject, template, **kwargs):
|
|
app = current_app._get_current_object()
|
|
msg = Message(
|
|
'{} {}'.format(app.config['NOPAQUE_MAIL_SUBJECT_PREFIX'], subject),
|
|
recipients=[to], sender=app.config['NOPAQUE_MAIL_SENDER'])
|
|
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
|
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
|
thread = Thread(target=send_async_email, args=(app, msg))
|
|
thread.start()
|
|
return thread
|