Created
October 31, 2015 00:22
-
-
Save Arty2/ec920de4de498fdb8e9e to your computer and use it in GitHub Desktop.
Sending email with python on WD My Cloud , see: https://community.wd.com/t/sending-email-with-python-on-wd-my-cloud/96006
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from email.header import Header | |
from email.mime.text import MIMEText | |
from getpass import getpass | |
from smtplib import SMTP_SSL | |
import sys | |
#edit the line below | |
login, password, server, recipients = "[email protected]", "password", "smtp.gmail.com", "[email protected]" | |
#send email | |
subject = sys.argv[1] | |
body = sys.argv[2] | |
msg = MIMEText(body, 'plain', 'utf-8') | |
msg['Subject'] = Header(subject, 'utf-8') | |
msg['From'] = login | |
msg['To'] = recipients | |
s = SMTP_SSL(server, 465, timeout=10) | |
s.set_debuglevel(1) | |
try: | |
s.login(login, password) | |
s.sendmail(msg['From'], recipients, msg.as_string()) | |
except Exception, error: | |
print "Unable to send e-mail: '%s'." % str(error) | |
finally: | |
s.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment