Skip to content

Instantly share code, notes, and snippets.

@rounakdatta
Created March 16, 2019 04:21
Show Gist options
  • Save rounakdatta/79a5243c5b0d8b4051220af2a66d0e9e to your computer and use it in GitHub Desktop.
Save rounakdatta/79a5243c5b0d8b4051220af2a66d0e9e to your computer and use it in GitHub Desktop.
Programmatically send emails through SMTP using Python (Yandex Mail)
def sendReportMail(emailAddress, passwordText, title, content):
import smtplib
from email.mime.text import MIMEText
smtp_ssl_host = 'smtp.yandex.com' # change to your own SMTP host
smtp_ssl_port = 465
username = emailAddress
password = passwordText
sender = emailAddress
targets = ['[email protected]']
msg = MIMEText(content)
msg['Subject'] = title
msg['From'] = sender
msg['To'] = ', '.join(targets)
server = smtplib.SMTP_SSL(smtp_ssl_host, smtp_ssl_port)
server.login(username, password)
server.sendmail(sender, targets, msg.as_string())
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment