2020-11-13 09:01:51 +00:00
|
|
|
from flask import current_app, render_template
|
2019-07-08 09:29:11 +00:00
|
|
|
from flask_mail import Message
|
|
|
|
from . import mail
|
2020-04-21 16:34:21 +00:00
|
|
|
from .decorators import background
|
2019-07-08 09:29:11 +00:00
|
|
|
|
|
|
|
|
2020-04-21 08:26:44 +00:00
|
|
|
def create_message(recipient, subject, template, **kwargs):
|
2020-11-13 09:01:51 +00:00
|
|
|
msg = Message('{} {}'.format(current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX'], subject), recipients=[recipient]) # noqa
|
2020-04-21 08:26:44 +00:00
|
|
|
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
|
|
|
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
|
|
|
return msg
|
|
|
|
|
|
|
|
|
2020-04-21 16:34:21 +00:00
|
|
|
@background
|
2020-04-27 12:08:59 +00:00
|
|
|
def send(msg, *args, **kwargs):
|
2021-09-22 11:51:45 +00:00
|
|
|
with kwargs['app'].app_context():
|
2019-07-08 09:29:11 +00:00
|
|
|
mail.send(msg)
|