-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmailme.py
32 lines (29 loc) · 927 Bytes
/
mailme.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
def send_email():
import smtplib
gmail_user = "user gmail ID"
gmail_pwd = "password"
FROM = '[email protected]'
TO = ['[email protected]'] #must be a list if more than one
SUBJECT = "Working??"
TEXT = "write whatever you want"
# actual message
message = """\From: %s\nTo: %s\nSubject: %s\n\n%s""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
#server = smtplib.SMTP(SERVER)
server = smtplib.SMTP("smtp.gmail.com", 587) #or port 465
print "print 1"
server.ehlo()
print "print 2"
server.starttls()
print "print 3"
server.ehlo()
server.login(gmail_user, gmail_pwd)
print "print 4"
server.sendmail(FROM, TO, message)
print "print 5"
#server.quit()
server.close()
print 'successfully sent the mail'
except:
print "failed to send mail"
send_email()