Skip to content

Instantly share code, notes, and snippets.

@metachu
Created December 14, 2011 21:58
Show Gist options
  • Save metachu/1478751 to your computer and use it in GitHub Desktop.
Save metachu/1478751 to your computer and use it in GitHub Desktop.
Send email via python
import smtplib
from email.MIMEText import MIMEText
GMAIL_LOGIN = '[email protected]'
GMAIL_PASSWORD = 'password'
def send_email(subject, message, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
msg = MIMEText(message)
msg['Subject'] = subject
msg['From'] = from_addr
msg['To'] = to_addr
server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
server.ehlo()
server.starttls()
server.ehlo()
server.login(GMAIL_LOGIN,GMAIL_PASSWORD)
server.sendmail(from_addr, to_addr, msg.as_string())
server.close()
if __name__=="__main__":
send_email('test', 'This is a test email')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment