Skip to content

Instantly share code, notes, and snippets.

@mitchtech
Created August 26, 2012 17:16
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
#!/usr/bin/env python
import smtplib
from email.mime.text import MIMEText
USERNAME = "username@gmail.com"
PASSWORD = "password"
MAILTO = "mailto@gmail.com"
msg = MIMEText('This is the body of the email')
msg['Subject'] = 'The email subject'
msg['From'] = USERNAME
msg['To'] = MAILTO
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo_or_helo_if_needed()
server.starttls()
server.ehlo_or_helo_if_needed()
server.login(USERNAME,PASSWORD)
server.sendmail(USERNAME, MAILTO, msg.as_string())
server.quit()
@skevas
Copy link

skevas commented May 23, 2016

@marcos10soares: The code does no longer work since Google improved its security standards. You have to create an app password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment