Skip to content

Instantly share code, notes, and snippets.

@scari
Created August 4, 2014 11:21
Show Gist options
  • Save scari/41ec8040478711fe9a48 to your computer and use it in GitHub Desktop.
Save scari/41ec8040478711fe9a48 to your computer and use it in GitHub Desktop.
send gmail
def send_gmail(to = None, subject = '', content = ''):
gmail_user = ""
gmail_pwd = ""
message = u'\From: {}\nTo: {}\nSubject: {}\n\n{}'.format(gmail_user, to, subject, content)
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_pwd)
server.sendmail(gmail_user, to, message)
server.close()
print 'succeed to send email to {}'.format(to)
except Exception as e:
print 'failed to send email to {}'.format(to)
raise e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment