Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(157758)

Side by Side Diff: Doc/includes/email-mime.py

Issue 10321: Add support for Message objects and binary data to smtplib.sendmail
Patch Set: Created 9 years, 1 month ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Doc/includes/email-simple.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Import smtplib for the actual sending function 1 # Import smtplib for the actual sending function
2 import smtplib 2 import smtplib
3 3
4 # Here are the email package modules we'll need 4 # Here are the email package modules we'll need
5 from email.mime.image import MIMEImage 5 from email.mime.image import MIMEImage
6 from email.mime.multipart import MIMEMultipart 6 from email.mime.multipart import MIMEMultipart
7 7
8 COMMASPACE = ', ' 8 COMMASPACE = ', '
9 9
10 # Create the container (outer) email message. 10 # Create the container (outer) email message.
11 msg = MIMEMultipart() 11 msg = MIMEMultipart()
12 msg['Subject'] = 'Our family reunion' 12 msg['Subject'] = 'Our family reunion'
13 # me == the sender's email address 13 # me == the sender's email address
14 # family = the list of all recipients' email addresses 14 # family = the list of all recipients' email addresses
15 msg['From'] = me 15 msg['From'] = me
16 msg['To'] = COMMASPACE.join(family) 16 msg['To'] = COMMASPACE.join(family)
17 msg.preamble = 'Our family reunion' 17 msg.preamble = 'Our family reunion'
18 18
19 # Assume we know that the image files are all in PNG format 19 # Assume we know that the image files are all in PNG format
20 for file in pngfiles: 20 for file in pngfiles:
21 # Open the files in binary mode. Let the MIMEImage class automatically 21 # Open the files in binary mode. Let the MIMEImage class automatically
22 # guess the specific image type. 22 # guess the specific image type.
23 fp = open(file, 'rb') 23 fp = open(file, 'rb')
24 img = MIMEImage(fp.read()) 24 img = MIMEImage(fp.read())
25 fp.close() 25 fp.close()
26 msg.attach(img) 26 msg.attach(img)
27 27
28 # Send the email via our own SMTP server. 28 # Send the email via our own SMTP server.
29 s = smtplib.SMTP() 29 s = smtplib.SMTP()
30 s.sendmail(me, family, msg.as_string()) 30 s.sendmail(msg)
31 s.quit() 31 s.quit()
OLDNEW
« no previous file with comments | « no previous file | Doc/includes/email-simple.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+