microblog/app/email.py

18 lines
482 B
Python
Raw Normal View History

2017-09-26 07:16:46 +00:00
from threading import Thread
from flask import current_app
2017-09-26 07:16:46 +00:00
from flask_mail import Message
from app import mail
2017-09-26 07:16:46 +00:00
def send_async_email(app, msg):
with app.app_context():
mail.send(msg)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender=sender, recipients=recipients)
msg.body = text_body
msg.html = html_body
Thread(target=send_async_email,
args=(current_app._get_current_object(), msg)).start()