/
generate.py
159 lines (149 loc) · 9.04 KB
/
generate.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
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def format(month1, date1, year1, month2, date2, year2, events_string, me, recipient):
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Department of Philosophy Talks & Events" + " (" + month1 + " " + date1 + " - " + month2 + " " + date2 + ", " + year2 + ")"
msg['From'] = me
msg['To'] = recipient
# Create the body of the message (a plain-text and an HTML version).
text = "Please mark your calendars with this listing of talks and events in the Department in the next two weeks.\nAlso, visit http://www.philosophy.utoronto.ca/events/ for a complete listing of upcoming talks and events."
html1 = """\
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-western"> <br>
<div class="moz-text-html" lang="x-western">
<blockquote cite="mid:546CC592.3070009@mail.utoronto.ca" type="cite">
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-western"><br>
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-western">
<div class="moz-text-html" lang="x-unicode">
<div dir="ltr">
<div class="gmail_quote">
<div text="#000000" bgcolor="#FFFFFF">
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div>
<div>
<div lang="x-western">
<blockquote type="cite">
<div lang="x-western">
<blockquote type="cite">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<div lang="x-western">
<table cellpadding="8" height="453" width="585" border="0">
<tbody>
<tr>
<td rowspan="1" colspan="1" bgcolor="#66ff99"><font face="Calibri" size="6"><b>The
U of T
Department of
Philosophy <br>
<big><small>Talks
and Events </small></big></b></font><font face="Calibri" size="6"><b>(""" + month1 + """</b><b> """ + date1 + ", " + year1 + " - " + month2 + " " + date2 + ", " + year2 + """)</font></font></b><font face="Calibri"><br>
<big>Please
mark your
calendars with
this listing
of talks and
events in the
Department in the next two weeks.
Also, </big></font><big><font face="Calibri">visit
</font></big><big><font face="Calibri"><a moz-do-not-send="true" href="http://www.philosophy.utoronto.ca/events/" target="_blank">http://www.philosophy.utoronto.ca/events/</a> </font></big><big><font face="Calibri">for
a complete
listing of
upcoming talks
and events. </font></big></td>
</tr>"""
html2 = """\
</tbody>
</table>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</body>
</html>"""
html = html1 + events_string + html2
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text, 'plain')
part2 = MIMEText(html, 'html')
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
# Send the message via gmail
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.ehlo()
s.login(me, "shhhhsecret!")
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, recipient, msg.as_string())
s.quit()
return ("Success! Internal Omnibus Sent! Check your email! Whooo!")