2007-08-15 11:28:22 -03:00
|
|
|
# Import smtplib for the actual sending function
|
|
|
|
import smtplib
|
|
|
|
|
|
|
|
# Here are the email package modules we'll need
|
|
|
|
from email.mime.image import MIMEImage
|
|
|
|
from email.mime.multipart import MIMEMultipart
|
|
|
|
|
|
|
|
COMMASPACE = ', '
|
|
|
|
|
|
|
|
# Create the container (outer) email message.
|
|
|
|
msg = MIMEMultipart()
|
|
|
|
msg['Subject'] = 'Our family reunion'
|
|
|
|
# me == the sender's email address
|
|
|
|
# family = the list of all recipients' email addresses
|
|
|
|
msg['From'] = me
|
|
|
|
msg['To'] = COMMASPACE.join(family)
|
|
|
|
msg.preamble = 'Our family reunion'
|
|
|
|
|
|
|
|
# Assume we know that the image files are all in PNG format
|
|
|
|
for file in pngfiles:
|
|
|
|
# Open the files in binary mode. Let the MIMEImage class automatically
|
|
|
|
# guess the specific image type.
|
2015-02-25 12:14:09 -04:00
|
|
|
with open(file, 'rb') as fp:
|
|
|
|
img = MIMEImage(fp.read())
|
2007-08-15 11:28:22 -03:00
|
|
|
msg.attach(img)
|
|
|
|
|
|
|
|
# Send the email via our own SMTP server.
|
2011-04-30 18:26:32 -03:00
|
|
|
s = smtplib.SMTP('localhost')
|
2010-11-20 17:28:24 -04:00
|
|
|
s.send_message(msg)
|
2009-04-26 17:25:45 -03:00
|
|
|
s.quit()
|