Last active
March 16, 2016 08:21
-
-
Save zlhaa23/c051dac4d1549d64a246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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