-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcise_send_function.py
More file actions
33 lines (25 loc) · 1.11 KB
/
concise_send_function.py
File metadata and controls
33 lines (25 loc) · 1.11 KB
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
from smtplib import SMTP_SSL as SMTP # this invokes the secure SMTP protocol (port 465, uses SSL)
# from smtplib import SMTP # use this for standard SMTP protocol (port 25, no encryption)
from email.mime.text import MIMEText
def send_mail(destination=['josvdwest@gmail.com'], subject="Subject", content="\nCompleted"):
# SMTPserver = 'smtp.att.yahoo.com'
sender = 'josvdwest@gmail.com'
PASSWORD = "" #Your gmail password
# typical values for text_subtype are plain, html, xml
text_subtype = 'plain'
try:
msg = MIMEText(content, text_subtype)
msg['Subject']= subject
msg['From'] = sender # some SMTP servers will do this automatically, not all
conn = SMTP('smtp.gmail.com')
conn.set_debuglevel(False)
conn.login(sender, PASSWORD)
try:
conn.sendmail(sender, destination, msg.as_string())
finally:
conn.quit()
except Exception, exc:
sys.exit( "mail failed; %s" % str(exc) ) # give a error message
#Quickly test the function
send_mail(["josvdwest@gmail.com"])
print("Done")