Skip to content

Instantly share code, notes, and snippets.

@liam-ob
Created October 6, 2023 03:24
Show Gist options
  • Save liam-ob/412bc56662fda88b0fde409c429648ff to your computer and use it in GitHub Desktop.
Save liam-ob/412bc56662fda88b0fde409c429648ff to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Send email via smtp_host."""
import smtplib
from email.mime.text import MIMEText
from email.header import Header
#smtp_host = 'smtp.live.com'
smtp_host = 'atteris-com-au.mail.protection.outlook.com'
login = "SENDEREMAIL"
password = "SENDERPASSWORD"
recipients_emails = ["RECIPIENTSEMAIL"]
msg = MIMEText('test message', 'plain', 'utf-8')
msg['Subject'] = Header('subject…', 'utf-8')
msg['From'] = login
msg['To'] = ", ".join(recipients_emails)
s = smtplib.SMTP_SSL(smtp_host, 465, timeout=10)
s.set_debuglevel(1)
try:
s.starttls()
s.login(login, password)
s.sendmail(msg['From'], recipients_emails, msg.as_string())
finally:
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment