Created
January 9, 2021 07:05
-
-
Save dealbreaker973/b1b4ae25d1fbe843c4b338984c1aeca4 to your computer and use it in GitHub Desktop.
python3 send email via gmail
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 | |
| gmail_user = '' # change this | |
| gmail_password = '' # change this | |
| #(if 2 FA are activated, you need to use app passwords | |
| sent_from = gmail_user | |
| to = ['', ''] # add receiver here | |
| subject = '' | |
| body = '' | |
| email_text = """\ | |
| From: {} | |
| To: {} | |
| Subject: {} | |
| {} | |
| """.format(sent_from, ", ".join(to), subject, body) | |
| try: | |
| server = smtplib.SMTP_SSL('smtp.gmail.com', 465) | |
| server.ehlo() | |
| server.login(gmail_user, gmail_password) | |
| server.sendmail(sent_from, to, email_text) | |
| server.close() | |
| print('Email sent!') | |
| except Exception as e: | |
| print('Something went wrong...') | |
| print(str(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment