Skip to content

Instantly share code, notes, and snippets.

@nathanhere
Created May 13, 2013 23:40
Show Gist options
  • Save nathanhere/5572465 to your computer and use it in GitHub Desktop.
Save nathanhere/5572465 to your computer and use it in GitHub Desktop.
Secure method to send emails from Python. Currently only works to send email to self, as more header information is needed for other servers.
from smtplib import SMTP_SSL
smtp = SMTP_SSL()
def emailUser():
from_who_alias = 'Jarvis'
from_who_real = 'sender@domain.com'
to = 'recipient@domain.com'
subject = 'Your Subject'
msg = 'Your message'
serverOut = 'smtpout.domain.net'
port = 465
pw = 'password'
content = '''\\\nFrom: {0}\nTo: {1}\nSubject: {2}\n\n\n{3}'''.format(from_who_alias, to, subject, msg)
smtp.connect(serverOut, port)
smtp.ehlo()
smtp.login(from_who_real, pw)
smtp.sendmail(from_who_real, to, content)
smtp.close()
emailUser()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment