-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.py
51 lines (44 loc) · 1.85 KB
/
mailer.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from flask import g, redirect, url_for, abort, \
render_template, flash
from bikeandwalk import app, db, mail
from flask_mail import Message
from views.utils import printException, cleanRecordID
from models import Organization
def sendInvite(assignment,user,countEventDict):
""" Send a single counting Assignment email """
hostName = app.config["HOST_NAME"]
organization = Organization.query.get(cleanRecordID(g.orgID))
with mail.record_messages() as outbox:
if user and assignment and organization:
subject = "Your assignment from %s" % (organization.name)
msg = Message( subject,
sender=(organization.name, organization.email),
recipients=[(user.name, user.email)])
msg.body = render_template("email/standardInvite.txt",
assignment=assignment,
countEventDict=countEventDict,
user=user,
hostName = hostName,
organization = organization,
)
msg.html = render_template("email/standardInvite.html",
assignment=assignment,
countEventDict=countEventDict,
user=user,
hostName = hostName,
organization = organization,
)
else:
mes = "Email is missing parameters"
printException(mes,"error",e)
return (False, mes)
try:
mail.send(msg)
except Exception as e:
mes = "Error Sending email"
printException(mes,"error",e)
return (False, mes)
if mail.suppress:
mes = '%d email(s) would have been sent if we were not testing' % (len(outbox))
return (True, mes )
return (True, "Email Sent Successfully")