Created
February 3, 2022 06:34
-
-
Save rammanokar/7a348bf45eab9956838e780a63ca6a31 to your computer and use it in GitHub Desktop.
send mail using python
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.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
gmail = { "host": "smtp.gmail.com", "port": 587 } | |
office365 = { "host": "smtp.office365.com", "port": 587 } | |
outlook = {"host": "smtp-mail.outlook.com", "port": 587 } | |
yahoo = { "host": "smtp.mail.yahoo.com", "port": 587 } | |
username = '*********@gmail.com' | |
password = 'Changeme' | |
mail_from = '[email protected]' | |
mail_to = '[email protected]' | |
mail_subject = "Test Subject" | |
mail_body = "This is a test message" | |
mimemsg = MIMEMultipart() | |
mimemsg['From']=mail_from | |
mimemsg['To']=mail_to | |
mimemsg['Subject']=mail_subject | |
mimemsg.attach(MIMEText(mail_body, 'plain')) | |
connection = smtplib.SMTP(host=gmail['host'], port=gmail['port']) | |
connection.starttls() | |
connection.login(username,password) | |
connection.send_message(mimemsg) | |
connection.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment