blob: 68533254620f0862af84268a2a6e3044837f6d1a [file] [log] [blame]
Barry Warsaw40ef0062006-03-18 15:41:53 +00001% Copyright (C) 2001-2006 Python Software Foundation
Barry Warsawbb113862004-10-03 03:16:19 +00002% Author: barry@python.org (Barry Warsaw)
Barry Warsaw5e634632001-09-26 05:23:47 +00003
Fred Drakea6a885b2001-09-26 16:52:18 +00004\section{\module{email} ---
Barry Warsaw5e634632001-09-26 05:23:47 +00005 An email and MIME handling package}
6
7\declaremodule{standard}{email}
8\modulesynopsis{Package supporting the parsing, manipulating, and
9 generating email messages, including MIME documents.}
Barry Warsawbb113862004-10-03 03:16:19 +000010\moduleauthor{Barry A. Warsaw}{barry@python.org}
11\sectionauthor{Barry A. Warsaw}{barry@python.org}
Barry Warsaw5e634632001-09-26 05:23:47 +000012
13\versionadded{2.2}
14
15The \module{email} package is a library for managing email messages,
16including MIME and other \rfc{2822}-based message documents. It
17subsumes most of the functionality in several older standard modules
Barry Warsawc5f8fe32001-09-26 22:21:52 +000018such as \refmodule{rfc822}, \refmodule{mimetools},
19\refmodule{multifile}, and other non-standard packages such as
Barry Warsaw5e17d202001-11-16 22:16:04 +000020\module{mimecntl}. It is specifically \emph{not} designed to do any
Barry Warsaw40ef0062006-03-18 15:41:53 +000021sending of email messages to SMTP (\rfc{2821}), NNTP, or other servers; those
22are functions of modules such as \refmodule{smtplib} and \refmodule{nntplib}.
23The \module{email} package attempts to be as RFC-compliant as possible,
24supporting in addition to \rfc{2822}, such MIME-related RFCs as
Barry Warsawbb113862004-10-03 03:16:19 +000025\rfc{2045}, \rfc{2046}, \rfc{2047}, and \rfc{2231}.
Barry Warsaw5e634632001-09-26 05:23:47 +000026
27The primary distinguishing feature of the \module{email} package is
28that it splits the parsing and generating of email messages from the
29internal \emph{object model} representation of email. Applications
30using the \module{email} package deal primarily with objects; you can
31add sub-objects to messages, remove sub-objects from messages,
32completely re-arrange the contents, etc. There is a separate parser
33and a separate generator which handles the transformation from flat
Andrew M. Kuchling43dc1fc2001-11-05 01:55:03 +000034text to the object model, and then back to flat text again. There
Barry Warsaw5e634632001-09-26 05:23:47 +000035are also handy subclasses for some common MIME object types, and a few
36miscellaneous utilities that help with such common tasks as extracting
37and parsing message field values, creating RFC-compliant dates, etc.
38
39The following sections describe the functionality of the
40\module{email} package. The ordering follows a progression that
41should be common in applications: an email message is read as flat
Barry Warsaw5db478f2002-10-01 04:33:16 +000042text from a file or other source, the text is parsed to produce the
43object structure of the email message, this structure is manipulated,
Barry Warsaw40ef0062006-03-18 15:41:53 +000044and finally, the object tree is rendered back into flat text.
Barry Warsaw5e634632001-09-26 05:23:47 +000045
Barry Warsaw5db478f2002-10-01 04:33:16 +000046It is perfectly feasible to create the object structure out of whole
47cloth --- i.e. completely from scratch. From there, a similar
48progression can be taken as above.
Barry Warsaw5e634632001-09-26 05:23:47 +000049
50Also included are detailed specifications of all the classes and
51modules that the \module{email} package provides, the exception
52classes you might encounter while using the \module{email} package,
53some auxiliary utilities, and a few examples. For users of the older
Barry Warsaw5b9da892002-10-01 01:05:52 +000054\module{mimelib} package, or previous versions of the \module{email}
55package, a section on differences and porting is provided.
Barry Warsaw5e634632001-09-26 05:23:47 +000056
Barry Warsaw5e17d202001-11-16 22:16:04 +000057\begin{seealso}
58 \seemodule{smtplib}{SMTP protocol client}
Barry Warsaw40ef0062006-03-18 15:41:53 +000059 \seemodule{nntplib}{NNTP protocol client}
Barry Warsaw5e17d202001-11-16 22:16:04 +000060\end{seealso}
61
Barry Warsaw5e634632001-09-26 05:23:47 +000062\subsection{Representing an email message}
Barry Warsawc5f8fe32001-09-26 22:21:52 +000063\input{emailmessage}
Barry Warsaw5e634632001-09-26 05:23:47 +000064
65\subsection{Parsing email messages}
Barry Warsawc5f8fe32001-09-26 22:21:52 +000066\input{emailparser}
Barry Warsaw5e634632001-09-26 05:23:47 +000067
68\subsection{Generating MIME documents}
Barry Warsawc5f8fe32001-09-26 22:21:52 +000069\input{emailgenerator}
Barry Warsaw5e634632001-09-26 05:23:47 +000070
71\subsection{Creating email and MIME objects from scratch}
Barry Warsaw5b9da892002-10-01 01:05:52 +000072\input{emailmimebase}
Barry Warsaw5e634632001-09-26 05:23:47 +000073
Barry Warsaw5db478f2002-10-01 04:33:16 +000074\subsection{Internationalized headers}
Barry Warsaw5b9da892002-10-01 01:05:52 +000075\input{emailheaders}
Barry Warsaw5e634632001-09-26 05:23:47 +000076
Barry Warsaw5db478f2002-10-01 04:33:16 +000077\subsection{Representing character sets}
78\input{emailcharsets}
79
Barry Warsawc5f8fe32001-09-26 22:21:52 +000080\subsection{Encoders}
81\input{emailencoders}
Barry Warsaw5e634632001-09-26 05:23:47 +000082
Barry Warsawbb113862004-10-03 03:16:19 +000083\subsection{Exception and Defect classes}
Barry Warsawc5f8fe32001-09-26 22:21:52 +000084\input{emailexc}
Barry Warsaw5e634632001-09-26 05:23:47 +000085
Barry Warsawc5f8fe32001-09-26 22:21:52 +000086\subsection{Miscellaneous utilities}
87\input{emailutil}
Barry Warsaw5e634632001-09-26 05:23:47 +000088
Barry Warsawc5f8fe32001-09-26 22:21:52 +000089\subsection{Iterators}
90\input{emailiter}
Barry Warsaw5e634632001-09-26 05:23:47 +000091
Barry Warsaw40ef0062006-03-18 15:41:53 +000092\subsection{Package History\label{email-pkg-history}}
Barry Warsaw5b9da892002-10-01 01:05:52 +000093
Barry Warsaw40ef0062006-03-18 15:41:53 +000094This table describes the release history of the email package, corresponding
95to the version of Python that the package was released with. For purposes of
96this document, when you see a note about change or added versions, these refer
97to the Python version the change was made it, \emph{not} the email package
98version. This table also describes the Python compatibility of each version
99of the package.
Barry Warsawbb113862004-10-03 03:16:19 +0000100
Barry Warsaw40ef0062006-03-18 15:41:53 +0000101\begin{tableiii}{l|l|l}{constant}{email version}{distributed with}{compatible with}
102\lineiii{1.x}{Python 2.2.0 to Python 2.2.1}{\emph{no longer supported}}
103\lineiii{2.5}{Python 2.2.2+ and Python 2.3}{Python 2.1 to 2.5}
104\lineiii{3.0}{Python 2.4}{Python 2.3 to 2.5}
105\lineiii{4.0}{Python 2.5}{Python 2.3 to 2.5}
106\end{tableiii}
Barry Warsawbb113862004-10-03 03:16:19 +0000107
Barry Warsaw40ef0062006-03-18 15:41:53 +0000108Here are the major differences between \module{email} verson 4 and version 3:
109
110\begin{itemize}
111\item All modules have been renamed according to \pep{8} standards. For
112 example, the version 3 module \module{email.Message} was renamed to
113 \module{email.message} in version 4.
114
115\item A new subpackage \module{email.mime} was added and all the version 3
116 \module{email.MIME*} modules were renamed and situated into the
117 \module{email.mime} subpackage. For example, the version 3 module
118 \module{email.MIMEText} was renamed to \module{email.mime.text}.
119
120 \emph{Note that the version 3 names will continue to work until Python
121 2.6}.
122
123\item The \module{email.mime.application} module was added, which contains the
124 \class{MIMEApplication} class.
125
126\item Methods that were deprecated in version 3 have been removed. These
127 include \method{Generator.__call__()}, \method{Message.get_type()},
128 \method{Message.get_main_type()}, \method{Message.get_subtype()}.
129\end{itemize}
130
131Here are the major differences between \module{email} version 3 and version 2:
Barry Warsawbb113862004-10-03 03:16:19 +0000132
133\begin{itemize}
134\item The \class{FeedParser} class was introduced, and the \class{Parser}
135 class was implemented in terms of the \class{FeedParser}. All parsing
Barry Warsaw40ef0062006-03-18 15:41:53 +0000136 therefore is non-strict, and parsing will make a best effort never to
Barry Warsawbb113862004-10-03 03:16:19 +0000137 raise an exception. Problems found while parsing messages are stored in
138 the message's \var{defect} attribute.
139
140\item All aspects of the API which raised \exception{DeprecationWarning}s in
141 version 2 have been removed. These include the \var{_encoder} argument
142 to the \class{MIMEText} constructor, the \method{Message.add_payload()}
143 method, the \function{Utils.dump_address_pair()} function, and the
144 functions \function{Utils.decode()} and \function{Utils.encode()}.
145
146\item New \exception{DeprecationWarning}s have been added to:
147 \method{Generator.__call__()}, \method{Message.get_type()},
148 \method{Message.get_main_type()}, \method{Message.get_subtype()}, and
149 the \var{strict} argument to the \class{Parser} class. These are
Barry Warsaw40ef0062006-03-18 15:41:53 +0000150 expected to be removed in future versions.
Barry Warsawbb113862004-10-03 03:16:19 +0000151
152\item Support for Pythons earlier than 2.3 has been removed.
153\end{itemize}
154
155Here are the differences between \module{email} version 2 and version 1:
Barry Warsaw5b9da892002-10-01 01:05:52 +0000156
157\begin{itemize}
158\item The \module{email.Header} and \module{email.Charset} modules
159 have been added.
Barry Warsawdd868d32002-10-01 15:29:09 +0000160
Barry Warsaw5b9da892002-10-01 01:05:52 +0000161\item The pickle format for \class{Message} instances has changed.
162 Since this was never (and still isn't) formally defined, this
Barry Warsaw5db478f2002-10-01 04:33:16 +0000163 isn't considered a backward incompatibility. However if your
Barry Warsaw5b9da892002-10-01 01:05:52 +0000164 application pickles and unpickles \class{Message} instances, be
165 aware that in \module{email} version 2, \class{Message}
166 instances now have private variables \var{_charset} and
167 \var{_default_type}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000168
Barry Warsaw5b9da892002-10-01 01:05:52 +0000169\item Several methods in the \class{Message} class have been
Barry Warsaw5db478f2002-10-01 04:33:16 +0000170 deprecated, or their signatures changed. Also, many new methods
Barry Warsaw5b9da892002-10-01 01:05:52 +0000171 have been added. See the documentation for the \class{Message}
Barry Warsaw5db478f2002-10-01 04:33:16 +0000172 class for details. The changes should be completely backward
Barry Warsaw5b9da892002-10-01 01:05:52 +0000173 compatible.
Barry Warsawdd868d32002-10-01 15:29:09 +0000174
Barry Warsaw5b9da892002-10-01 01:05:52 +0000175\item The object structure has changed in the face of
176 \mimetype{message/rfc822} content types. In \module{email}
177 version 1, such a type would be represented by a scalar payload,
178 i.e. the container message's \method{is_multipart()} returned
Barry Warsaw5db478f2002-10-01 04:33:16 +0000179 false, \method{get_payload()} was not a list object, but a single
180 \class{Message} instance.
Barry Warsaw5b9da892002-10-01 01:05:52 +0000181
182 This structure was inconsistent with the rest of the package, so
183 the object representation for \mimetype{message/rfc822} content
Barry Warsaw5db478f2002-10-01 04:33:16 +0000184 types was changed. In \module{email} version 2, the container
Barry Warsaw5b9da892002-10-01 01:05:52 +0000185 \emph{does} return \code{True} from \method{is_multipart()}, and
186 \method{get_payload()} returns a list containing a single
187 \class{Message} item.
188
Barry Warsaw5db478f2002-10-01 04:33:16 +0000189 Note that this is one place that backward compatibility could
Barry Warsaw5b9da892002-10-01 01:05:52 +0000190 not be completely maintained. However, if you're already
191 testing the return type of \method{get_payload()}, you should be
192 fine. You just need to make sure your code doesn't do a
193 \method{set_payload()} with a \class{Message} instance on a
194 container with a content type of \mimetype{message/rfc822}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000195
Barry Warsaw5b9da892002-10-01 01:05:52 +0000196\item The \class{Parser} constructor's \var{strict} argument was
197 added, and its \method{parse()} and \method{parsestr()} methods
198 grew a \var{headersonly} argument. The \var{strict} flag was
199 also added to functions \function{email.message_from_file()}
200 and \function{email.message_from_string()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000201
Barry Warsaw5b9da892002-10-01 01:05:52 +0000202\item \method{Generator.__call__()} is deprecated; use
203 \method{Generator.flatten()} instead. The \class{Generator}
204 class has also grown the \method{clone()} method.
Barry Warsawdd868d32002-10-01 15:29:09 +0000205
Barry Warsaw5b9da892002-10-01 01:05:52 +0000206\item The \class{DecodedGenerator} class in the
207 \module{email.Generator} module was added.
Barry Warsawdd868d32002-10-01 15:29:09 +0000208
Barry Warsaw5b9da892002-10-01 01:05:52 +0000209\item The intermediate base classes \class{MIMENonMultipart} and
210 \class{MIMEMultipart} have been added, and interposed in the
Barry Warsaw5db478f2002-10-01 04:33:16 +0000211 class hierarchy for most of the other MIME-related derived
Barry Warsaw5b9da892002-10-01 01:05:52 +0000212 classes.
Barry Warsawdd868d32002-10-01 15:29:09 +0000213
Barry Warsaw5b9da892002-10-01 01:05:52 +0000214\item The \var{_encoder} argument to the \class{MIMEText} constructor
215 has been deprecated. Encoding now happens implicitly based
216 on the \var{_charset} argument.
Barry Warsawdd868d32002-10-01 15:29:09 +0000217
Barry Warsaw5b9da892002-10-01 01:05:52 +0000218\item The following functions in the \module{email.Utils} module have
219 been deprecated: \function{dump_address_pairs()},
220 \function{decode()}, and \function{encode()}. The following
221 functions have been added to the module:
222 \function{make_msgid()}, \function{decode_rfc2231()},
223 \function{encode_rfc2231()}, and \function{decode_params()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000224
Barry Warsaw5b9da892002-10-01 01:05:52 +0000225\item The non-public function \function{email.Iterators._structure()}
226 was added.
227\end{itemize}
228
Barry Warsaw5e634632001-09-26 05:23:47 +0000229\subsection{Differences from \module{mimelib}}
230
231The \module{email} package was originally prototyped as a separate
Barry Warsawc5f8fe32001-09-26 22:21:52 +0000232library called
233\ulink{\module{mimelib}}{http://mimelib.sf.net/}.
234Changes have been made so that
Barry Warsaw5e634632001-09-26 05:23:47 +0000235method names are more consistent, and some methods or modules have
236either been added or removed. The semantics of some of the methods
237have also changed. For the most part, any functionality available in
Fred Drake90e68782001-09-27 20:09:39 +0000238\module{mimelib} is still available in the \refmodule{email} package,
Barry Warsaw5db478f2002-10-01 04:33:16 +0000239albeit often in a different way. Backward compatibility between
240the \module{mimelib} package and the \module{email} package was not a
241priority.
Barry Warsaw5e634632001-09-26 05:23:47 +0000242
243Here is a brief description of the differences between the
Fred Drake90e68782001-09-27 20:09:39 +0000244\module{mimelib} and the \refmodule{email} packages, along with hints on
Barry Warsaw5e634632001-09-26 05:23:47 +0000245how to port your applications.
246
247Of course, the most visible difference between the two packages is
Fred Drake90e68782001-09-27 20:09:39 +0000248that the package name has been changed to \refmodule{email}. In
Barry Warsaw5e634632001-09-26 05:23:47 +0000249addition, the top-level package has the following differences:
250
251\begin{itemize}
252\item \function{messageFromString()} has been renamed to
253 \function{message_from_string()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000254
Barry Warsaw5e634632001-09-26 05:23:47 +0000255\item \function{messageFromFile()} has been renamed to
256 \function{message_from_file()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000257
Barry Warsaw5e634632001-09-26 05:23:47 +0000258\end{itemize}
259
260The \class{Message} class has the following differences:
261
262\begin{itemize}
263\item The method \method{asString()} was renamed to \method{as_string()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000264
Barry Warsaw5e634632001-09-26 05:23:47 +0000265\item The method \method{ismultipart()} was renamed to
266 \method{is_multipart()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000267
Barry Warsaw5e634632001-09-26 05:23:47 +0000268\item The \method{get_payload()} method has grown a \var{decode}
269 optional argument.
Barry Warsawdd868d32002-10-01 15:29:09 +0000270
Barry Warsaw5e634632001-09-26 05:23:47 +0000271\item The method \method{getall()} was renamed to \method{get_all()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000272
Barry Warsaw5e634632001-09-26 05:23:47 +0000273\item The method \method{addheader()} was renamed to \method{add_header()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000274
Barry Warsaw5e634632001-09-26 05:23:47 +0000275\item The method \method{gettype()} was renamed to \method{get_type()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000276
Georg Brandl89f000e2005-06-04 10:01:15 +0000277\item The method \method{getmaintype()} was renamed to
Barry Warsaw5e634632001-09-26 05:23:47 +0000278 \method{get_main_type()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000279
Barry Warsaw5e634632001-09-26 05:23:47 +0000280\item The method \method{getsubtype()} was renamed to
281 \method{get_subtype()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000282
Barry Warsaw5e634632001-09-26 05:23:47 +0000283\item The method \method{getparams()} was renamed to
284 \method{get_params()}.
285 Also, whereas \method{getparams()} returned a list of strings,
286 \method{get_params()} returns a list of 2-tuples, effectively
Barry Warsawc5f8fe32001-09-26 22:21:52 +0000287 the key/value pairs of the parameters, split on the \character{=}
Barry Warsaw5e634632001-09-26 05:23:47 +0000288 sign.
Barry Warsawdd868d32002-10-01 15:29:09 +0000289
Barry Warsaw5e634632001-09-26 05:23:47 +0000290\item The method \method{getparam()} was renamed to \method{get_param()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000291
Barry Warsaw5e634632001-09-26 05:23:47 +0000292\item The method \method{getcharsets()} was renamed to
293 \method{get_charsets()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000294
Barry Warsaw5e634632001-09-26 05:23:47 +0000295\item The method \method{getfilename()} was renamed to
296 \method{get_filename()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000297
Barry Warsaw5e634632001-09-26 05:23:47 +0000298\item The method \method{getboundary()} was renamed to
299 \method{get_boundary()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000300
Barry Warsaw5e634632001-09-26 05:23:47 +0000301\item The method \method{setboundary()} was renamed to
302 \method{set_boundary()}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000303
Barry Warsaw5e634632001-09-26 05:23:47 +0000304\item The method \method{getdecodedpayload()} was removed. To get
305 similar functionality, pass the value 1 to the \var{decode} flag
306 of the {get_payload()} method.
Barry Warsawdd868d32002-10-01 15:29:09 +0000307
Barry Warsaw5e634632001-09-26 05:23:47 +0000308\item The method \method{getpayloadastext()} was removed. Similar
309 functionality
310 is supported by the \class{DecodedGenerator} class in the
Barry Warsaw40ef0062006-03-18 15:41:53 +0000311 \refmodule{email.generator} module.
Barry Warsawdd868d32002-10-01 15:29:09 +0000312
Barry Warsaw5e634632001-09-26 05:23:47 +0000313\item The method \method{getbodyastext()} was removed. You can get
314 similar functionality by creating an iterator with
315 \function{typed_subpart_iterator()} in the
Barry Warsaw40ef0062006-03-18 15:41:53 +0000316 \refmodule{email.iterators} module.
Barry Warsaw5e634632001-09-26 05:23:47 +0000317\end{itemize}
318
319The \class{Parser} class has no differences in its public interface.
320It does have some additional smarts to recognize
Fred Drakea6a885b2001-09-26 16:52:18 +0000321\mimetype{message/delivery-status} type messages, which it represents as
Barry Warsaw5e634632001-09-26 05:23:47 +0000322a \class{Message} instance containing separate \class{Message}
323subparts for each header block in the delivery status
324notification\footnote{Delivery Status Notifications (DSN) are defined
Fred Drake90e68782001-09-27 20:09:39 +0000325in \rfc{1894}.}.
Barry Warsaw5e634632001-09-26 05:23:47 +0000326
327The \class{Generator} class has no differences in its public
Barry Warsaw40ef0062006-03-18 15:41:53 +0000328interface. There is a new class in the \refmodule{email.generator}
Barry Warsaw5e634632001-09-26 05:23:47 +0000329module though, called \class{DecodedGenerator} which provides most of
330the functionality previously available in the
331\method{Message.getpayloadastext()} method.
332
333The following modules and classes have been changed:
334
335\begin{itemize}
336\item The \class{MIMEBase} class constructor arguments \var{_major}
337 and \var{_minor} have changed to \var{_maintype} and
338 \var{_subtype} respectively.
Barry Warsawdd868d32002-10-01 15:29:09 +0000339
Barry Warsaw5e634632001-09-26 05:23:47 +0000340\item The \code{Image} class/module has been renamed to
341 \code{MIMEImage}. The \var{_minor} argument has been renamed to
342 \var{_subtype}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000343
Barry Warsaw5e634632001-09-26 05:23:47 +0000344\item The \code{Text} class/module has been renamed to
345 \code{MIMEText}. The \var{_minor} argument has been renamed to
346 \var{_subtype}.
Barry Warsawdd868d32002-10-01 15:29:09 +0000347
Barry Warsaw5e634632001-09-26 05:23:47 +0000348\item The \code{MessageRFC822} class/module has been renamed to
349 \code{MIMEMessage}. Note that an earlier version of
350 \module{mimelib} called this class/module \code{RFC822}, but
351 that clashed with the Python standard library module
352 \refmodule{rfc822} on some case-insensitive file systems.
353
354 Also, the \class{MIMEMessage} class now represents any kind of
Fred Drakea6a885b2001-09-26 16:52:18 +0000355 MIME message with main type \mimetype{message}. It takes an
Barry Warsaw5e634632001-09-26 05:23:47 +0000356 optional argument \var{_subtype} which is used to set the MIME
Fred Drakea6a885b2001-09-26 16:52:18 +0000357 subtype. \var{_subtype} defaults to \mimetype{rfc822}.
Barry Warsaw5e634632001-09-26 05:23:47 +0000358\end{itemize}
359
360\module{mimelib} provided some utility functions in its
361\module{address} and \module{date} modules. All of these functions
Barry Warsaw40ef0062006-03-18 15:41:53 +0000362have been moved to the \refmodule{email.utils} module.
Barry Warsaw5e634632001-09-26 05:23:47 +0000363
364The \code{MsgReader} class/module has been removed. Its functionality
365is most closely supported in the \function{body_line_iterator()}
Barry Warsaw40ef0062006-03-18 15:41:53 +0000366function in the \refmodule{email.iterators} module.
Barry Warsaw5e634632001-09-26 05:23:47 +0000367
368\subsection{Examples}
369
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000370Here are a few examples of how to use the \module{email} package to
371read, write, and send simple email messages, as well as more complex
372MIME messages.
373
374First, let's see how to create and send a simple text message:
375
Fred Drakefcc31b42002-10-01 14:17:10 +0000376\verbatiminput{email-simple.py}
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000377
378Here's an example of how to send a MIME message containing a bunch of
Barry Warsawea66abc2002-10-01 04:48:06 +0000379family pictures that may be residing in a directory:
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000380
Fred Drakefcc31b42002-10-01 14:17:10 +0000381\verbatiminput{email-mime.py}
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000382
Fred Drake7934bc22003-01-29 05:10:27 +0000383Here's an example of how to send the entire contents of a directory as
384an email message:
385\footnote{Thanks to Matthew Dixon Cowles for the original inspiration
386 and examples.}
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000387
Fred Drakefcc31b42002-10-01 14:17:10 +0000388\verbatiminput{email-dir.py}
Barry Warsaw2bb077f2001-11-05 17:50:53 +0000389
390And finally, here's an example of how to unpack a MIME message like
391the one above, into a directory of files:
392
Fred Drakefcc31b42002-10-01 14:17:10 +0000393\verbatiminput{email-unpack.py}