Skip to content

Instantly share code, notes, and snippets.

@rammanokar
Created February 3, 2022 06:34
Show Gist options
  • Save rammanokar/7a348bf45eab9956838e780a63ca6a31 to your computer and use it in GitHub Desktop.
Save rammanokar/7a348bf45eab9956838e780a63ca6a31 to your computer and use it in GitHub Desktop.
send mail using python
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