in server/app/lib/email.py [0:0]
def from_template(template_filename: str, recipient: str, variables: dict, thread_start: bool=False, thread_key: str=None):
"""generate and send email from template"""
template_path = os.path.join(config.messaging.template_dir, template_filename)
assert os.path.isfile(template_path), f"Could not find template {template_path}"
template_data = open(template_path).read()
subject, body = template_data.split("--", maxsplit=1)
asfpy.messaging.mail(
sender=config.messaging.sender,
recipient=recipient,
subject=subject.strip().format(**variables),
message=body.strip().format(**variables),
thread_start=thread_start,
thread_key=thread_key,
headers={},
)