summaryrefslogtreecommitdiffstats
path: root/Doc/lib/email-mime.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2002-10-01 14:17:10 (GMT)
committerFred Drake <fdrake@acm.org>2002-10-01 14:17:10 (GMT)
commitfcc31b44d24e8e8bddc19b27c916a051223e5164 (patch)
tree2ceccfbe3d8dc6f73f94cb919d7c6c8fd1398c45 /Doc/lib/email-mime.py
parentea66abc6e2b5d9e88f7c91aee5cea6d331b0a288 (diff)
downloadcpython-fcc31b44d24e8e8bddc19b27c916a051223e5164.zip
cpython-fcc31b44d24e8e8bddc19b27c916a051223e5164.tar.gz
cpython-fcc31b44d24e8e8bddc19b27c916a051223e5164.tar.bz2
Split the long email package examples into separate files and use
\verbatiminput instead of the verbatim environment -- this does the "right thing" regarding page breaks in long examples for the typeset formats, and has nice benefits for the HTML version as well.
Diffstat (limited to 'Doc/lib/email-mime.py')
-rw-r--r--Doc/lib/email-mime.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/Doc/lib/email-mime.py b/Doc/lib/email-mime.py
new file mode 100644
index 0000000..28c8d2e
--- /dev/null
+++ b/Doc/lib/email-mime.py
@@ -0,0 +1,34 @@
+# Import smtplib for the actual sending function
+import smtplib
+
+# Here are the email pacakge modules we'll need
+from email.MIMEImage import MIMEImage
+from email.MIMEMultipart 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'
+# Guarantees the message ends in a newline
+msg.epilogue = ''
+
+# 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.
+ fp = open(file, 'rb')
+ img = MIMEImage(fp.read())
+ fp.close()
+ msg.attach(img)
+
+# Send the email via our own SMTP server.
+s = smtplib.SMTP()
+s.connect()
+s.sendmail(me, family, msg.as_string())
+s.close()