blob: a90edc1373726ad6faa2397c1a475aa145f2da2b [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001# Import smtplib for the actual sending function
2import smtplib
3
4# Here are the email package modules we'll need
5from email.mime.image import MIMEImage
6from email.mime.multipart import MIMEMultipart
7
8COMMASPACE = ', '
9
10# Create the container (outer) email message.
11msg = MIMEMultipart()
12msg['Subject'] = 'Our family reunion'
13# me == the sender's email address
14# family = the list of all recipients' email addresses
15msg['From'] = me
16msg['To'] = COMMASPACE.join(family)
17msg.preamble = 'Our family reunion'
18
19# Assume we know that the image files are all in PNG format
20for file in pngfiles:
21 # Open the files in binary mode. Let the MIMEImage class automatically
22 # guess the specific image type.
23 fp = open(file, 'rb')
24 img = MIMEImage(fp.read())
25 fp.close()
26 msg.attach(img)
27
28# Send the email via our own SMTP server.
R David Murraybb754b52011-04-30 17:26:32 -040029s = smtplib.SMTP('localhost')
R. David Murray8b9f0c52010-11-20 21:28:24 +000030s.send_message(msg)
Jeroen Ruigrok van der Werven939c1782009-04-26 20:25:45 +000031s.quit()