Last active
August 29, 2015 14:05
-
-
Save shapiromatron/1700c76e316b88a57dca to your computer and use it in GitHub Desktop.
send email using gmail and built-in python smtplib
This file contains hidden or 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
| import smtplib | |
| def send_email(email, pw, subject, text): | |
| FROM = email | |
| TO = [email] | |
| try: | |
| message = """\From: %s\nTo: %s\nSubject: %s\n\n%s\n""" % (FROM, ", ".join(TO), subject, text) | |
| server = smtplib.SMTP("smtp.gmail.com", 587) # alternatively port 465 | |
| server.ehlo() | |
| server.starttls() | |
| server.login(email, pw) | |
| server.sendmail(FROM, TO, message) | |
| server.close() | |
| print 'successfully sent the mail' | |
| except: | |
| print "failed to send mail" | |
| if __name__ == "__main__": | |
| email = "swiss_cheese@gmail.com" | |
| pw = "emmental " | |
| send_email(email, pw, "testing", "here we go...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment