mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-07-05 20:23:17 +00:00
Change email function names
This commit is contained in:
22
app/email.py
22
app/email.py
@ -4,18 +4,24 @@ from threading import Thread
|
||||
from . import mail
|
||||
|
||||
|
||||
def send_async_email(app, msg):
|
||||
def create_message(recipient, subject, template, **kwargs):
|
||||
app = current_app._get_current_object()
|
||||
sender = app.config['NOPAQUE_MAIL_SENDER']
|
||||
subject_prefix = app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
|
||||
msg = Message('{} {}'.format(subject_prefix, subject),
|
||||
recipients=[recipient], sender=sender)
|
||||
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
||||
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
||||
return msg
|
||||
|
||||
|
||||
def send(app, msg):
|
||||
with app.app_context():
|
||||
mail.send(msg)
|
||||
|
||||
|
||||
def send_email(to, subject, template, **kwargs):
|
||||
def send_async(msg):
|
||||
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 = Thread(target=send, args=(app, msg))
|
||||
thread.start()
|
||||
return thread
|
||||
|
Reference in New Issue
Block a user