Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gene1wood/d82cd0ff296f5846eb48 to your computer and use it in GitHub Desktop.
Save gene1wood/d82cd0ff296f5846eb48 to your computer and use it in GitHub Desktop.
Simple example of how to send email in Python through authenticated SMTP
fromaddr = 'me@example.com'
toaddr = 'you@example.org'
servername = 'smtp.example.com'
username = 'username'
password = 'password'
import smtplib
import time
server = smtplib.SMTP(servername, 25)
server.set_debuglevel(1)
server.login(username, password)
msg='''From: %(from)s\nTo: %(to)s\nSubject: This is a test sent at %(date)s\nThis is a test sent at %(date)s
''' % {'from' : fromaddr, 'to': toaddr, 'date': time.strftime('%x %X')}
server.sendmail(fromaddr, toaddr, msg)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment