Skip to content

Instantly share code, notes, and snippets.

@klingtnet
Created October 28, 2019 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klingtnet/833b4b22b894f36e367860bacba4a236 to your computer and use it in GitHub Desktop.
Save klingtnet/833b4b22b894f36e367860bacba4a236 to your computer and use it in GitHub Desktop.
Send emails with Python using SMTP over TLS
import smtplib
import os
from email.message import EmailMessage
with smtplib.SMTP_SSL('mailserver.example', port=465) as smtp:
smtp.login('my-user', 'my-secret-password')
from_addr = 'my-user@mailserver.example'
to_addr = 'anli@spreadshirt.net'
msg = EmailMessage()
msg.set_content('This is a test.')
msg['Subject'] = 'A test subject'
msg['From'] = from_addr
msg['To'] = to_addr
smtp.send_message(msg, from_addr, to_addr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment