Skip to content

Instantly share code, notes, and snippets.

@skyler
Created August 13, 2012 15:17
Show Gist options
  • Save skyler/3341732 to your computer and use it in GitHub Desktop.
Save skyler/3341732 to your computer and use it in GitHub Desktop.
Send an email through a Gmail account
import smtplib
import string
gmail_user = ""
gmail_pwd = ""
def send_mail(to, subject, text):
email = string.join((
"From: %s" % gmail_user,
"To: %s" % to,
"Subject: %s" % subject,
"",
text,
), "\r\n")
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(gmail_user, gmail_pwd)
server.sendmail(gmail_user, to, email)
server.close()
send_mail("[email protected]", "Message from Python", "Test Body")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment