forked from miguelgrinberg/microblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemails.py
29 lines (23 loc) · 895 Bytes
/
emails.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from flask import render_template
from flask.ext.mail import Message
from app import mail
from .decorators import async
from config import ADMINS
from app import app
@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("[microblog] %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))