Created
April 13, 2019 18:49
-
-
Save theArjun/c6068faed16ab29698975507c1e3ec0a to your computer and use it in GitHub Desktop.
Send Email from Python using 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
| RECEIPENT_EMAIL = '' | |
| SENDER_EMAIL = '' | |
| PASSWORD = '' |
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, config | |
| def send_email(subject, msg): | |
| try: | |
| server = smtplib.SMTP('smtp.gmail.com:587') | |
| server.ehlo() | |
| server.starttls() | |
| server.login(config.SENDER_EMAIL, config.PASSWORD) | |
| message = 'Subject: {} {}'.format(subject, msg) | |
| server.sendmail(config.SENDER_EMAIL, config.RECEIPENT_EMAIL, message) | |
| server.quit() | |
| print("Message sent successfully.") | |
| except: | |
| print("Message send failed.") | |
| subject = 'Hello Man' | |
| msg = 'How are you? Been a long time.' | |
| send_email(subject, msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment