1# Import smtplib for the actual sending function. 2import smtplib 3 4# Here are the email package modules we'll need. 5from email.message import EmailMessage 6 7# Create the container email message. 8msg = EmailMessage() 9msg['Subject'] = 'Our family reunion' 10# me == the sender's email address 11# family = the list of all recipients' email addresses 12msg['From'] = me 13msg['To'] = ', '.join(family) 14msg.preamble = 'You will not see this in a MIME-aware mail reader.\n' 15 16# Open the files in binary mode. You can also omit the subtype 17# if you want MIMEImage to guess it. 18for file in pngfiles: 19 with open(file, 'rb') as fp: 20 img_data = fp.read() 21 msg.add_attachment(img_data, maintype='image', 22 subtype='png') 23 24# Send the email via our own SMTP server. 25with smtplib.SMTP('localhost') as s: 26 s.send_message(msg) 27