-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemailInterface.py
246 lines (213 loc) · 11.7 KB
/
emailInterface.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
'''
Methods used in deploying emails
'''
import datetime
import logging
import config
from dbtools import waveTools
from google.appengine.api import mail
def sendFirstNotificationEmail(url, wave_id, wavelet_id, send_to, who_modified, wave_title, message=""):
'''
Sends the first notification email to the user
@param url: this users unique url
@param wave_id: the id of the wave that the email is about
@param wavelet_id: the id of the wavelet that the email is about
@param send_to: the email receipient to sent the email to
@param who_modified: who modified the wave and triggered the email
@param wave_title: the title of the wave
@param message="": the personalized message that was sent by the adder
'''
if _isEmailValid(send_to):
logging.info("Sending first notification email to " + send_to)
#Fetch the meta wave object
metaWave = waveTools.get(wave_id, wavelet_id)
#Sort the message content variables for sending
wave_title = wave_title or "Untitled"
message = message or "No message was left"
display_name = _getDisplayName(metaWave, who_modified)
invitor = display_name + " (" + who_modified + ")"
text_variables = { 'title' : wave_title,
'invitor' : invitor,
'message' : message,
'url' : url,
'time' : datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S'),
'robot_web' : config.ROBOT_WEB}
#Generate the address and subject
sender_address = config.ROBOT_EMAIL_SENDER_NAME + " <" + config.ROBOT_EMAIL_SEND_NOTIFICATION + ">"
subject = "Invitation to join: " + wave_title
#Send!
mail.send_mail( sender_address,
send_to,
subject,
FIRST_NOTIFICATION_PLAIN % text_variables,
html=FIRST_NOTIFICATION_HTML % text_variables)
logging.info("Mail sent successfully to " + send_to)
def sendNotificationEmail(url, wave_id, wavelet_id, send_to, who_modified, wave_title, who_modified_display=None):
'''
Sends a notification email to the user
@param url: this users unique url
@param wave_id: the id of the wave that the email is about
@param wavelet_id: the id of the wavelet that the email is about
@param send_to: the email receipient to sent the email to
@param who_modified: who modified the wave and triggered the email
@param wave_title: the title of the wave
@param who_modified_display=None: a friendly name of who modified the wave. If None then a friendly name is retrieved from wave meta
'''
if _isEmailValid(send_to):
logging.info("Sending notification email to " + send_to)
#Fetch the meta wave object
metaWave = waveTools.get(wave_id, wavelet_id)
#Sort the message content variables for sending
wave_title = wave_title or "Untitled"
display_name = who_modified_display or _getDisplayName(metaWave, who_modified)
invitor = display_name + " (" + who_modified + ")"
text_variables = { 'title' : wave_title,
'modifier' : invitor,
'url' : url,
'time' : datetime.datetime.now().strftime('%d-%m-%Y %H:%M:%S'),
'robot_web' : config.ROBOT_WEB}
#Generate the address and subject
sender_address = config.ROBOT_EMAIL_SENDER_NAME + " <" + config.ROBOT_EMAIL_SEND_NOTIFICATION + ">"
subject = "Update: " + wave_title
mail.send_mail( sender_address,
send_to,
subject,
REPLY_NOTIFICATION_PLAIN % text_variables,
html=REPLY_NOTIFICATION_HTML % text_variables)
logging.info("Mail sent successfully to " + send_to)
def _getDisplayName(metaWave, who_modified):
'''
@param metaWave: a metaWave object from the datastore
@param who_modified: the person who modified the message
@return the friendly name or who_modified if not found
'''
try:
return metaWave.participant_profiles.get(who_modified, None).get('displayName', None) or who_modified
except:
return who_modified
def _isEmailValid(email):
'''
Performs some validation checks on the email address. This could be used
to prevent blacklisted address' in the future
@param email: the email address to check
@return True if and only if the email address is valid
'''
return mail.is_email_valid(email)
################################################################################
# Email content (HTML)
################################################################################
FIRST_NOTIFICATION_HTML = \
"""
<table width="100%%" border="0" cellspacing="0" bordercolor="gray">
<tr><td>
<table width="100%%" border="0" cellspacing="10" style="font-family:arial, sans-serif; font-size:small;">
<tr>
<td width="77px" height="77px">
<img src="%(robot_web)sweb/media/icon.png" title="Mr Ray logo" alt="Mr Ray logo" height="75" width="75" style="border:1px solid #CAD0D9; font-size:xx-small;"/>
</td>
<td>
<p style="font-size:medium; font-weight:bold;">Mr Ray, the wav-e-mail bot</p>
</td>
</tr>
<tr>
<td colspan=2><p><b>You have been invited to take part in a conversation on Google Wave using the Mr-Ray service. This means you don't need a Google Wave account. All you have to do is click on the link provided and get started!</b></p><br /></td>
</tr>
<tr>
<td style="color:gray;">Wave:</td><td>%(title)s</td>
</tr>
<tr>
<td style="color:gray;">By:</td><td>%(invitor)s</td>
</tr>
<tr>
<td style="color:gray;">Invitation Message:</td><td>%(message)s</td>
</tr>
<tr>
<td style="color:gray;">Your link:</td><td>Please don't share <a href="%(url)s">your secret link!</a></td>
</tr>
</table>
</td></tr>
<tr><td style="color:gray; font-family:arial, sans-serif; font-size:xx-small; background-color:#F6F6F6">
<p><b>What is Mr-Ray and why have I been sent this e-mail?</b></p>
<p>Mr-Ray is a free service that allows you to communicate with Google Wave users without needing an account. Someone on Google Wave wanted to invite you into their conversation. You can find more details about <a href="http://wave.google.com/about.html">Google Wave</a> and the <a href="https://github.com/waveto/mr-ray-open">Mr-Ray</a> service using the links provided.</p>
<p><b>Why shouldn't I share the link that was sent to me?</b><p>
<p>This link is unique to you and your e-mail address. Sharing it will allow other people to reply as you.</p>
<p><b>I don't want any more notifications about this wave, what should I do?</b></p>
<p>Don't worry. Just ignore this e-mail. You will only receive more notifications if you visit the link we provided.</p>
<br />
<p>Mail sent at %(time)s</p>
<p>Do not reply to this email address it is not monitored. You will not receive any new notifications about updates to the wave until you have visited the url.</p>
</td></tr>
</table>
"""
REPLY_NOTIFICATION_HTML = \
"""
<table width="100%%" border="0" cellspacing="0" bordercolor="gray">
<tr><td>
<table width="100%%" border="0" cellspacing="10" style="font-family:arial, sans-serif; font-size:small;">
<tr>
<td width="77px" height="77px">
<img src="%(robot_web)sweb/media/icon.png" title="Mr Ray logo" alt="Mr Ray logo" height="75" width="75" style="border:1px solid #CAD0D9; font-size:xx-small;"/>
</td>
<td>
<p style="font-size:medium; font-weight:bold;">Mr Ray, the wav-e-mail bot</p>
</td>
</tr>
<tr>
<td colspan=2><p><b>A Wave that you follow has been updated. We thought you might want to see the changes!</b></p><br /></td>
</tr>
<tr>
<td style="color:gray;">Wave:</td><td>%(title)s</td>
</tr>
<tr>
<td style="color:gray;">By:</td><td>%(modifier)s</td>
</tr>
<tr>
<td style="color:gray;">Your link:</td><td>Please don't share <a href="%(url)s">your secret link!</a></td>
</tr>
</table>
</td></tr>
<tr><td style="color:gray; font-family:arial, sans-serif; font-size:xx-small; background-color:#F6F6F6">
<p><b>Why shouldn't I share the link that was sent to me?</b><p>
<p>This link is unique to you and your e-mail address. Sharing it will allow other people to reply as you.</p>
<p><b>I don't want any more notifications about this wave, what should I do?</b></p>
<p>Don't worry. Just ignore this e-mail. You will only receive more notifications if you visit the link we provided.</p>
<br />
<p>Mail sent at %(time)s</p>
<p>Do not reply to this email address it is not monitored. You will not receive any new notifications about updates to the wave until you have visited the url.</p>
</td></tr>
</table>
"""
################################################################################
# Email content (Plain)
################################################################################
FIRST_NOTIFICATION_PLAIN = \
"""
You have been invited to take part in a conversation on Google Wave using the Mr-Ray service. This means you don't need a Google Wave account. All you have to do is click on the link provided and get started!
Wave: %(title)s
By: %(invitor)s
Invitation Message: %(message)s
Your link: Please don't share your secret link: %(url)s
************************
*What is Mr-Ray and why have I been sent this e-mail?
Mr-Ray is a free service that allows you to communicate with Google Wave users without needing an account. Someone on Google Wave wanted to invite you into their conversation. You can find more details about Google Wave(http://wave.google.com/about.html) and the Mr-Ray service(https://github.com/waveto/mr-ray-open) service using the links provided.
*Why shouldn't I share the link that was sent to me?
This link is unique to you and your e-mail address. Sharing it will allow other people to reply as you.
*I don't want any more notifications about this wave, what should I do?
Don't worry. Just ignore this e-mail. You will only receive more notifications if you visit the link we provided.
Mail sent at %(time)s
Do not reply to this email address it is not monitored. You will not receive any new notifications about updates to the wave until you have visited the url.
"""
REPLY_NOTIFICATION_PLAIN = \
"""
A Wave that you follow has been updated. We thought you might want to see the changes!
Wave: %(title)s
By: %(modifier)s
Your link: Please don't share your secret link: %(url)s
************************
*Why shouldn't I share the link that was sent to me?
This link is unique to you and your e-mail address. Sharing it will allow other people to reply as you.
*I don't want any more notifications about this wave, what should I do?
Don't worry. Just ignore this e-mail. You will only receive more notifications if you visit the link we provided.
Mail sent at %(time)s
Do not reply to this email address it is not monitored. You will not receive any new notifications about updates to the wave until you have visited the url.
"""