mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
28 lines
710 B
Python
28 lines
710 B
Python
from flask import current_app, render_template
|
|
from flask_mail import Message
|
|
from typing import Any, Text
|
|
from . import mail
|
|
from .decorators import background
|
|
|
|
|
|
def create_message(
|
|
recipient: str,
|
|
subject: str,
|
|
template: str,
|
|
**kwargs: Any
|
|
) -> Message:
|
|
subject_prefix: str = current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX']
|
|
msg: Message = Message(
|
|
f'{subject_prefix} {subject}',
|
|
recipients=[recipient]
|
|
)
|
|
msg.body = render_template(f'{template}.txt.j2', **kwargs)
|
|
msg.html = render_template(f'{template}.html.j2', **kwargs)
|
|
return msg
|
|
|
|
|
|
@background
|
|
def send(msg: Message, *args, **kwargs):
|
|
with kwargs['app'].app_context():
|
|
mail.send(msg)
|