-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailconfirm.py
executable file
·76 lines (59 loc) · 2.55 KB
/
emailconfirm.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
"""
This script contains a function that will email a confirmation after someone
has signed up for a help request item. If they did not provide an email address,
the contact will be sent an email notifying them of this event.
"""
from __future__ import absolute_import, division, print_function
import web
import model
from datetime import datetime, timedelta
import config
import utils
web.config.smtp_server = config.SMTP_SERVER
web.config.smtp_port = config.SMTP_PORT
web.config.smtp_username = config.SMTP_USER
web.config.smtp_password = config.SMTP_PASS
web.config.smtp_starttls = True
def sendConfirmationEmail(item_id):
# don't even attempt if email config info has not been provided
if not web.config.smtp_username:
print("WARNING: email user/password not configured. Ignoring attempt to send confirmation email.")
return
item = model.get_item(int(item_id))
# Get contact info for the help item
post_data = model.get_post(int(item.helpRequestId))
contact_data = model.get_contact_data(post_data.contactId)
item.contactName = contact_data.name
item.contactEmail = contact_data.email
item.contactPhone = contact_data.phone
item.url = "%s/view/%s" % (config.SITE_BASE, item.helpRequestId)
item.date = utils.convert_date(item.date)
if item.helpEmail:
f = web.config.smtp_username
to = item.helpEmail
cc = item.contactEmail
subject = 'Confirmation: you signed up to help on %(date)s' % item
msg = """Thanks for you willingness to help.
This email is to confirm that you signed up to help on %(date)s for the item "%(description)s". More details can be found here:
%(url)s
If you have any questions don't reply to this email. Instead contact %(contactName)s
email: %(contactEmail)s
phone: %(contactPhone)s
Thanks!""" % item
#print f, to, subject, msg
web.sendmail(f,to,subject,msg,cc=cc)
else:
# The person did not provide an email. Instead an email will be sent
# to the contact person informing them of the situation.
f = web.config.smtp_username
to = item.contactEmail
subject = 'Confirmation: Helper with no email'
msg = """%(helpName)s signed up to help on %(date)s for item
"%(description)s" but did not provide an email address.
Since no email is present, the website will be unable to provide them an automatic reminder.
Details can be found here:
%(url)s
""" % item
#print f, to, subject, msg
web.sendmail(f,to,subject,msg)