Skip to content
Snippets Groups Projects
email.py 585 B
Newer Older
  • Learn to ignore specific revisions
  • from flask import current_app, render_template
    
    Patrick Jentsch's avatar
    Patrick Jentsch committed
    from flask_mail import Message
    from . import mail
    
    from .decorators import background
    
    def create_message(recipient, subject, template, **kwargs):
    
        msg = Message('{} {}'.format(current_app.config['NOPAQUE_MAIL_SUBJECT_PREFIX'], subject), recipients=[recipient])  # noqa
    
        msg.body = render_template('{}.txt.j2'.format(template), **kwargs)
        msg.html = render_template('{}.html.j2'.format(template), **kwargs)
        return msg
    
    
    
    Patrick Jentsch's avatar
    Patrick Jentsch committed
    def send(msg, *args, **kwargs):
    
    Patrick Jentsch's avatar
    Patrick Jentsch committed
        with kwargs['app'].app_context():
    
    Patrick Jentsch's avatar
    Patrick Jentsch committed
            mail.send(msg)