Skip to content

Instantly share code, notes, and snippets.

@mshuffett
Created March 30, 2014 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mshuffett/9873851 to your computer and use it in GitHub Desktop.
Save mshuffett/9873851 to your computer and use it in GitHub Desktop.
Send email using Gmail
import smtplib
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
def sendmail(message, subject='subject', username='username', password='password', address='reciever'):
msg = MIMEMultipart()
msg['From'] = username
msg['To'] = address
msg['Subject'] = subject
msg.attach(MIMEText(message, 'plain'))
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login(username, password)
text = msg.as_string()
server.sendmail(username, address, text)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment