Created
August 4, 2014 11:21
-
-
Save scari/41ec8040478711fe9a48 to your computer and use it in GitHub Desktop.
send gmail
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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