Created
October 28, 2019 14:13
-
-
Save klingtnet/833b4b22b894f36e367860bacba4a236 to your computer and use it in GitHub Desktop.
Send emails with Python using SMTP over TLS
This file contains 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 | |
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