Skip to content

Instantly share code, notes, and snippets.

@saggie
Last active December 7, 2022 02:08
Show Gist options
  • Save saggie/d5dd304c8d77c0a69631a340ecb4f5a9 to your computer and use it in GitHub Desktop.
Save saggie/d5dd304c8d77c0a69631a340ecb4f5a9 to your computer and use it in GitHub Desktop.
Sending an email with Python
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