Created
September 24, 2012 20:26
-
-
Save hjerpbakk/3778152 to your computer and use it in GitHub Desktop.
Send an email via Gmail using Python. From http://hjerpbakk.com/blog/2012/9/24/send-an-email-via-gmail-using-python.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import smtplib | |
import string | |
def send_email(to_address, subject, body): | |
from_address = '' | |
username = from_address | |
password = '' | |
email = string.join(( | |
'From: %s' % from_address, | |
'To: %s' % to_address, | |
'Subject: %s' % subject, | |
'', | |
body | |
), '\r\n') | |
server = smtplib.SMTP('smtp.gmail.com:587') | |
server.ehlo() | |
server.starttls() | |
server.login(username, password) | |
server.sendmail(from_address, to_address, email) | |
server.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment