2020-10-08 12:34:02 +02:00
|
|
|
from flask import render_template
|
2019-07-08 11:29:11 +02:00
|
|
|
from flask_mail import Message
|
|
|
|
from . import mail
|
2020-04-21 18:34:21 +02:00
|
|
|
from .decorators import background
|
2019-07-08 11:29:11 +02:00
|
|
|
|
|
|
|
|
2020-04-21 10:26:44 +02:00
|
|
|
def create_message(recipient, subject, template, **kwargs):
|
2020-10-08 12:34:02 +02:00
|
|
|
msg = Message('[nopaque] {}'.format(subject), recipients=[recipient])
|
2020-04-21 10:26:44 +02:00
|
|
|
msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
|
|
|
|
msg.html = render_template('{}.html.j2'.format(template), **kwargs)
|
|
|
|
return msg
|
|
|
|
|
|
|
|
|
2020-04-21 18:34:21 +02:00
|
|
|
@background
|
2020-04-27 14:08:59 +02:00
|
|
|
def send(msg, *args, **kwargs):
|
|
|
|
app = kwargs['app']
|
2019-07-08 11:29:11 +02:00
|
|
|
with app.app_context():
|
|
|
|
mail.send(msg)
|