Last active
December 7, 2022 02:08
-
-
Save saggie/d5dd304c8d77c0a69631a340ecb4f5a9 to your computer and use it in GitHub Desktop.
Sending an email with Python
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 | |
from email.message import EmailMessage | |
textfile = 'textfile' | |
with open(textfile) as fp: | |
msg = EmailMessage() | |
msg.set_content(fp.read()) | |
msg['Subject'] = f'The contents of {textfile}' | |
msg['From'] = 'from@example.com' | |
msg['To'] = 'to@example.com' | |
smtp = smtplib.SMTP('smtp@example.com') | |
smtp.send_message(msg) | |
smtp.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment