-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_pinky_email.py
53 lines (46 loc) · 1.84 KB
/
send_pinky_email.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
# Code taken from
# http://jmduke.com/posts/how-to-send-emails-through-python-and-gmail/
#
# Google Apps SMTP settings:
# https://support.google.com/a/answer/176600?hl=en
from smtplib import SMTP
import os, sys
projectpath = os.path.dirname(__file__)
sys.path.append(projectpath)
import gmail
GMAIL_USERNAME = gmail.username
GMAIL_PASSWORD = gmail.password
# Build the email
email_subject = '\\\\pinky is back up!'
recipients = gmail.recipients
headers = '\r\n'.join(['from: Phil Wright <' + GMAIL_USERNAME + '>',
'subject: ' + email_subject,
'to: ' + recipients[0],
'mime-version: 1.0',
'content-type: text/html'])
body_of_email = """
<html>
Folks,<br><br>
The PINKY server has been restored to service,
and you should be able to create APS and key
cutting files on it now as needed. Please
contact me if you continue to experience issues
with this process.<br><br>
Thanks!<br><br>
Phil
</html>
"""
content = headers + "\r\n\r\n" + body_of_email
# Create session
# session = smtplib.SMTP('smtp.gmail.com', 587)
# Changed port to 25 after getting timeout error with 587 & 465
with SMTP('smtp.gmail.com', 25) as session:
#session = smtplib.SMTP('smtp.gmail.com', 25)
session.ehlo()
session.starttls()
# Next line failed until I changed my "Less secure apps" setting at
# https://www.google.com/settings/security/lesssecureapps
# (See https://support.google.com/accounts/answer/6010255 )
session.login(GMAIL_USERNAME, GMAIL_PASSWORD)
# Send the email!
session.sendmail(GMAIL_USERNAME, recipients, content)