X-Git-Url: http://git.datanom.net/flask-test.git/blobdiff_plain/db4f0ba9d4aec596f179335f1d86b3dd2bb206c6..163c4d87c8cefd45e8c8836daa28c53956be1e1a:/app/emails.py diff --git a/app/emails.py b/app/emails.py new file mode 100644 index 0000000..7febbb4 --- /dev/null +++ b/app/emails.py @@ -0,0 +1,27 @@ +from flask_mail import Message +from app import mail +from app import app +from flask import render_template +from config import ADMINS +from .decorators import async + +@async +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 + send_async_email(app, msg) + +def follower_notification(followed, follower): + send_email("[WPP] %s is now following you!" % follower.nickname, + ADMINS[0], + [followed.email], + render_template("follower_email.txt", + user=followed, follower=follower), + render_template("follower_email.html", + user=followed, follower=follower)) +