Mailing List Archive

python/dist/src/Doc/lib email.tex,1.13,1.14
Update of /cvsroot/python/python/dist/src/Doc/lib
In directory usw-pr-cvs1:/tmp/cvs-serv21417

Modified Files:
email.tex
Log Message:
Cleaned up the examples.


Index: email.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/lib/email.tex,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** email.tex 1 Oct 2002 04:33:12 -0000 1.13
--- email.tex 1 Oct 2002 04:48:06 -0000 1.14
***************
*** 290,302 ****
import smtplib

! # Here are the email pacakge modules we'll need
! from email import Encoders
from email.MIMEText import MIMEText

! # Open a plain text file for reading
! fp = open(textfile)
! # Create a text/plain message, using Quoted-Printable encoding for non-ASCII
! # characters.
! msg = MIMEText(fp.read(), _encoder=Encoders.encode_quopri)
fp.close()

--- 290,301 ----
import smtplib

! # Import the email modules we'll need
from email.MIMEText import MIMEText

! # Open a plain text file for reading. For this example, assume that
! # the text file contains only ASCII characters.
! fp = open(textfile, 'rb')
! # Create a text/plain message
! msg = MIMEText(fp.read())
fp.close()

***************
*** 307,320 ****
msg['To'] = you

! # Send the message via our own SMTP server. Use msg.as_string() with
! # unixfrom=0 so as not to confuse SMTP.
s = smtplib.SMTP()
s.connect()
! s.sendmail(me, [you], msg.as_string(0))
s.close()
\end{verbatim}

Here's an example of how to send a MIME message containing a bunch of
! family pictures:

\begin{verbatim}
--- 306,319 ----
msg['To'] = you

! # Send the message via our own SMTP server, but don't include the
! # envelope header.
s = smtplib.SMTP()
s.connect()
! s.sendmail(me, [you], msg.as_string())
s.close()
\end{verbatim}

Here's an example of how to send a MIME message containing a bunch of
! family pictures that may be residing in a directory:

\begin{verbatim}
***************
*** 324,336 ****
# Here are the email pacakge modules we'll need
from email.MIMEImage import MIMEImage
! from email.MIMEBase import MIMEBase

COMMASPACE = ', '

# Create the container (outer) email message.
# me == the sender's email address
# family = the list of all recipients' email addresses
- msg = MIMEBase('multipart', 'mixed')
- msg['Subject'] = 'Our family reunion'
msg['From'] = me
msg['To'] = COMMASPACE.join(family)
--- 323,335 ----
# 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)
***************
*** 341,345 ****
# Assume we know that the image files are all in PNG format
for file in pngfiles:
# guess the specific image type.
fp = open(file, 'rb')
--- 340,344 ----
# Assume we know that the image files are all in PNG format
for file in pngfiles:
# guess the specific image type.
fp = open(file, 'rb')
***************
*** 351,355 ****
s = smtplib.SMTP()
s.connect()
! s.sendmail(me, family, msg.as_string(unixfrom=0))
s.close()
\end{verbatim}
--- 350,354 ----
s = smtplib.SMTP()
s.connect()
! s.sendmail(me, family, msg.as_string())
s.close()
\end{verbatim}
***************
*** 395,399 ****
from email.Message import Message
from email.MIMEAudio import MIMEAudio
! from email.MIMEBase import MIMEBase
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
--- 394,398 ----
from email.Message import Message
from email.MIMEAudio import MIMEAudio
! from email.MIMEMultipart import MIMEMultipart
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
***************
*** 429,433 ****

# Create the enclosing (outer) message
! outer = MIMEBase('multipart', 'mixed')
outer['Subject'] = 'Contents of directory %s' % os.path.abspath(dir)
outer['To'] = COMMASPACE.join(recips)
--- 428,432 ----

# Create the enclosing (outer) message
! outer = MIMEMultipart()
outer['Subject'] = 'Contents of directory %s' % os.path.abspath(dir)
outer['To'] = COMMASPACE.join(recips)
***************
*** 441,447 ****
if not os.path.isfile(path):
continue
# will be ignored, although we should check for simple things like
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
--- 440,446 ----
if not os.path.isfile(path):
continue
# will be ignored, although we should check for simple things like
! # gzip'd or compressed files.
ctype, encoding = mimetypes.guess_type(path)
if ctype is None or encoding is not None:
***************
*** 466,470 ****
fp = open(path, 'rb')
msg = MIMEBase(maintype, subtype)
! msg.add_payload(fp.read())
fp.close()
# Encode the payload using Base64
--- 465,469 ----
fp = open(path, 'rb')
msg = MIMEBase(maintype, subtype)
! msg.set_payload(fp.read())
fp.close()
# Encode the payload using Base64
***************
*** 474,485 ****
outer.attach(msg)

- fp = open('/tmp/debug.pck', 'w')
- import cPickle
- cPickle.dump(outer, fp)
- fp.close()
# Now send the message
s = smtplib.SMTP()
s.connect()
! s.sendmail(sender, recips, outer.as_string(0))
s.close()

--- 473,480 ----
outer.attach(msg)

# Now send the message
s = smtplib.SMTP()
s.connect()
! s.sendmail(sender, recips, outer.as_string())
s.close()

***************
*** 557,561 ****
for part in msg.walk():
# multipart/* are just containers
! if part.get_main_type() == 'multipart':
continue
# Applications should really sanitize the given filename so that an
--- 552,556 ----
for part in msg.walk():
# multipart/* are just containers
! if part.get_content_maintype() == 'multipart':
continue
# Applications should really sanitize the given filename so that an