Skip to content

Instantly share code, notes, and snippets.

@Arty2
Created October 31, 2015 00:22
Show Gist options
  • Save Arty2/ec920de4de498fdb8e9e to your computer and use it in GitHub Desktop.
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
#!/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 = "youremail@gmail.com", "password", "smtp.gmail.com", "recipient@domain.com"
#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