Last active
March 9, 2022 04:30
-
-
Save pyaephyohein/1d9ffca7e81c9c6d8d0f101f769f6aa9 to your computer and use it in GitHub Desktop.
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
| from datetime import date | |
| import email | |
| from dotenv import load_dotenv | |
| import os | |
| import smtplib | |
| import ssl | |
| load_dotenv() | |
| email = os.getenv('email') | |
| password = os.getenv('password') | |
| host = os.getenv('host') | |
| port = os.getenv('port') | |
| # to = os.getenv('receiver') | |
| sent_from = email | |
| to = ['pyaephyohein.info.3326@gmail.com', 'pyae.phyohein@outlook.com'] | |
| subject = 'Test Email from python' | |
| cmd = os.system('date') | |
| body = str(cmd) | |
| print(body) | |
| print (to) | |
| email_text = """\ | |
| From: %s | |
| To: %s | |
| Subject: %s | |
| %s | |
| """ % (sent_from, ", ".join(to), subject, str(body)) | |
| context = ssl.create_default_context() | |
| try: | |
| smtp_server = smtplib.SMTP(host, port) | |
| smtp_server.ehlo() | |
| smtp_server.starttls() | |
| smtp_server.login(email, password) | |
| smtp_server.sendmail(sent_from, to, email_text) | |
| smtp_server.close() | |
| print ("Email sent successfully!") | |
| except Exception as ex: | |
| print ("Something went wrong….",ex) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment