Skip to content

Instantly share code, notes, and snippets.

@zlhaa23
Last active March 16, 2016 08:21
Show Gist options
  • Save zlhaa23/c051dac4d1549d64a246 to your computer and use it in GitHub Desktop.
Save zlhaa23/c051dac4d1549d64a246 to your computer and use it in GitHub Desktop.
'''
Example:
python email_notify.py smtp-mail.outlook.com 587 ######## from@outlook.com to@outlook.com "Hello from Python" "Lunch is ready"
'''
import sys
import smtplib
from email.mime.text import MIMEText
_, host, port, password, fromaddr, toaddr, subject, content = sys.argv
msg = MIMEText(content)
msg['Subject'] = subject
msg['From'] = fromaddr
msg['To'] = toaddr
s = smtplib.SMTP(host, port)
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.ehlo()
s.login(fromaddr, password)
try:
# Python 3
s.send_message(msg)
except AttributeError:
# Python 2
s.sendmail(msg['From'], [msg['To']], msg.as_string())
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment