mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00

* Deprecate imghdr Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Update Doc/whatsnew/3.11.rst Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> * Inline `imghdr` into `email.mime.image` Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com> Co-authored-by: Barry Warsaw <barry@python.org>
26 lines
849 B
Python
26 lines
849 B
Python
# Import smtplib for the actual sending function
|
|
import smtplib
|
|
|
|
# Here are the email package modules we'll need
|
|
from email.message import EmailMessage
|
|
|
|
# Create the container email message.
|
|
msg = EmailMessage()
|
|
msg['Subject'] = 'Our family reunion'
|
|
# me == the sender's email address
|
|
# family = the list of all recipients' email addresses
|
|
msg['From'] = me
|
|
msg['To'] = ', '.join(family)
|
|
msg.preamble = 'You will not see this in a MIME-aware mail reader.\n'
|
|
|
|
# Open the files in binary mode. Use imghdr to figure out the
|
|
# MIME subtype for each specific image.
|
|
for file in pngfiles:
|
|
with open(file, 'rb') as fp:
|
|
img_data = fp.read()
|
|
msg.add_attachment(img_data, maintype='image',
|
|
subtype='jpeg')
|
|
|
|
# Send the email via our own SMTP server.
|
|
with smtplib.SMTP('localhost') as s:
|
|
s.send_message(msg)
|