Skip to content

Instantly share code, notes, and snippets.

@galvez
Created October 14, 2010 23:26
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save galvez/627275 to your computer and use it in GitHub Desktop.
def try_sending_email():
import os, smtplib, mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Encoders import encode_base64
gmail_user = '[user]@gmail.com'
gmail_password = '[password]'
recipient = '[recipient]'
msg = MIMEMultipart()
msg['From'] = gmail_user
msg['To'] = recipient
msg['Subject'] = 'Hello!'
msg.attach(MIMEText('Hello'))
mail_server = smtplib.SMTP('smtp.gmail.com', 587)
mail_server.set_debuglevel(1)
mail_server.ehlo()
mail_server.starttls()
mail_server.ehlo()
mail_server.login(gmail_user, gmail_password)
mail_server.sendmail(gmail_user, recipient, msg.as_string())
mail_server.close()
print('Sent email to %s' % recipient)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment