Created
January 12, 2023 22:37
-
-
Save makesomelayouts/918b7f7e6518ec5fa4bcf1fba3077b78 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
| import smtplib | |
| from email.mime.text import MIMEText | |
| from passwords import EMAIL, EMAIL_APP_PASSWORD | |
| def send_email(message): | |
| sender = EMAIL | |
| recipient = EMAIL | |
| password = EMAIL_APP_PASSWORD | |
| server = smtplib.SMTP('smtp.gmail.com', 587) | |
| server.starttls() | |
| try: | |
| server.login(sender, password) | |
| msg = MIMEText(message) | |
| msg['Subject'] = 'Hello! This is message sent from python.' | |
| server.sendmail(sender, recipient, msg.as_string()) | |
| return 'Msg sent.' | |
| except Exception as e: | |
| return e | |
| def main(): | |
| msg = input() | |
| print(send_email(message=msg)) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment