Skip to content

Instantly share code, notes, and snippets.

@alaudet
Last active August 29, 2015 14:02
Show Gist options
  • Save alaudet/afc10137539b68d39228 to your computer and use it in GitHub Desktop.
Save alaudet/afc10137539b68d39228 to your computer and use it in GitHub Desktop.
smtplib gmail
import smtplib
import string
def smtp_gmail():
username = "your smtp username here "
password = "your smtp password here"
smtp_server = "smtp.gmail.com:587"
email_from = "sender email"
email_to = "recipient email or wireless carrier sms #"
email_body = string.join((
"From: %s" % email_from,
"To: %s" % email_to,
"Subject: This is my subject line!",
"",
"This is my message that can also have a %s" % (mystring
),), "\r\n"
)
server = smtplib.SMTP(smtp_server)
server.starttls()
server.login(username, password)
server.sendmail(email_from, email_to, email_body)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment