blob: 4735be3237ff3ce860781c85aa2d2a5cf430d553 [file] [log] [blame]
Barry Warsaw40ef0062006-03-18 15:41:53 +00001\declaremodule{standard}{email.mime}
2\declaremodule{standard}{email.mime.base}
3\declaremodule{standard}{email.mime.nonmultipart}
4\declaremodule{standard}{email.mime.multipart}
5\declaremodule{standard}{email.mime.audio}
6\declaremodule{standard}{email.mime.image}
7\declaremodule{standard}{email.mime.message}
8\declaremodule{standard}{email.mime.text}
Barry Warsaw5b9da892002-10-01 01:05:52 +00009Ordinarily, you get a message object structure by passing a file or
Barry Warsaw5db478f2002-10-01 04:33:16 +000010some text to a parser, which parses the text and returns the root
11message object. However you can also build a complete message
12structure from scratch, or even individual \class{Message} objects by
13hand. In fact, you can also take an existing structure and add new
14\class{Message} objects, move them around, etc. This makes a very
15convenient interface for slicing-and-dicing MIME messages.
Barry Warsaw5b9da892002-10-01 01:05:52 +000016
Barry Warsaw40ef0062006-03-18 15:41:53 +000017You can create a new object structure by creating \class{Message} instances,
18adding attachments and all the appropriate headers manually. For MIME
19messages though, the \module{email} package provides some convenient
20subclasses to make things easier.
Barry Warsaw5b9da892002-10-01 01:05:52 +000021
22Here are the classes:
23
24\begin{classdesc}{MIMEBase}{_maintype, _subtype, **_params}
Barry Warsaw40ef0062006-03-18 15:41:53 +000025Module: \module{email.mime.base}
26
Barry Warsaw5b9da892002-10-01 01:05:52 +000027This is the base class for all the MIME-specific subclasses of
28\class{Message}. Ordinarily you won't create instances specifically
29of \class{MIMEBase}, although you could. \class{MIMEBase} is provided
30primarily as a convenient base class for more specific MIME-aware
31subclasses.
32
33\var{_maintype} is the \mailheader{Content-Type} major type
34(e.g. \mimetype{text} or \mimetype{image}), and \var{_subtype} is the
35\mailheader{Content-Type} minor type
36(e.g. \mimetype{plain} or \mimetype{gif}). \var{_params} is a parameter
37key/value dictionary and is passed directly to
38\method{Message.add_header()}.
39
40The \class{MIMEBase} class always adds a \mailheader{Content-Type} header
41(based on \var{_maintype}, \var{_subtype}, and \var{_params}), and a
42\mailheader{MIME-Version} header (always set to \code{1.0}).
43\end{classdesc}
44
45\begin{classdesc}{MIMENonMultipart}{}
Barry Warsaw40ef0062006-03-18 15:41:53 +000046Module: \module{email.mime.nonmultipart}
47
Barry Warsaw5b9da892002-10-01 01:05:52 +000048A subclass of \class{MIMEBase}, this is an intermediate base class for
49MIME messages that are not \mimetype{multipart}. The primary purpose
50of this class is to prevent the use of the \method{attach()} method,
51which only makes sense for \mimetype{multipart} messages. If
52\method{attach()} is called, a \exception{MultipartConversionError}
53exception is raised.
54
55\versionadded{2.2.2}
56\end{classdesc}
57
58\begin{classdesc}{MIMEMultipart}{\optional{subtype\optional{,
59 boundary\optional{, _subparts\optional{, _params}}}}}
Barry Warsaw40ef0062006-03-18 15:41:53 +000060Module: \module{email.mime.multipart}
Barry Warsaw5b9da892002-10-01 01:05:52 +000061
62A subclass of \class{MIMEBase}, this is an intermediate base class for
63MIME messages that are \mimetype{multipart}. Optional \var{_subtype}
64defaults to \mimetype{mixed}, but can be used to specify the subtype
65of the message. A \mailheader{Content-Type} header of
66\mimetype{multipart/}\var{_subtype} will be added to the message
67object. A \mailheader{MIME-Version} header will also be added.
68
69Optional \var{boundary} is the multipart boundary string. When
70\code{None} (the default), the boundary is calculated when needed.
71
72\var{_subparts} is a sequence of initial subparts for the payload. It
73must be possible to convert this sequence to a list. You can always
74attach new subparts to the message by using the
75\method{Message.attach()} method.
76
77Additional parameters for the \mailheader{Content-Type} header are
78taken from the keyword arguments, or passed into the \var{_params}
79argument, which is a keyword dictionary.
80
81\versionadded{2.2.2}
82\end{classdesc}
83
Barry Warsaw40ef0062006-03-18 15:41:53 +000084\begin{classdesc}{MIMEApplication}{_data\optional{, _subtype\optional{,
85 _encoder\optional{, **_params}}}}
86Module: \module{email.mime.application}
87
88A subclass of \class{MIMENonMultipart}, the \class{MIMEApplication} class is
89used to represent MIME message objects of major type \mimetype{application}.
90\var{_data} is a string containing the raw byte data. Optional \var{_subtype}
91specifies the MIME subtype and defaults to \mimetype{octet-stream}.
92
93Optional \var{_encoder} is a callable (i.e. function) which will
94perform the actual encoding of the data for transport. This
95callable takes one argument, which is the \class{MIMEApplication} instance.
96It should use \method{get_payload()} and \method{set_payload()} to
97change the payload to encoded form. It should also add any
98\mailheader{Content-Transfer-Encoding} or other headers to the message
99object as necessary. The default encoding is base64. See the
100\refmodule{email.encoders} module for a list of the built-in encoders.
101
102\var{_params} are passed straight through to the base class constructor.
103\versionadded{2.5}
104\end{classdesc}
105
Barry Warsaw5b9da892002-10-01 01:05:52 +0000106\begin{classdesc}{MIMEAudio}{_audiodata\optional{, _subtype\optional{,
107 _encoder\optional{, **_params}}}}
Barry Warsaw40ef0062006-03-18 15:41:53 +0000108Module: \module{email.mime.audio}
Barry Warsaw5b9da892002-10-01 01:05:52 +0000109
110A subclass of \class{MIMENonMultipart}, the \class{MIMEAudio} class
111is used to create MIME message objects of major type \mimetype{audio}.
112\var{_audiodata} is a string containing the raw audio data. If this
113data can be decoded by the standard Python module \refmodule{sndhdr},
114then the subtype will be automatically included in the
115\mailheader{Content-Type} header. Otherwise you can explicitly specify the
116audio subtype via the \var{_subtype} parameter. If the minor type could
117not be guessed and \var{_subtype} was not given, then \exception{TypeError}
118is raised.
119
120Optional \var{_encoder} is a callable (i.e. function) which will
121perform the actual encoding of the audio data for transport. This
122callable takes one argument, which is the \class{MIMEAudio} instance.
123It should use \method{get_payload()} and \method{set_payload()} to
124change the payload to encoded form. It should also add any
125\mailheader{Content-Transfer-Encoding} or other headers to the message
Barry Warsaw5db478f2002-10-01 04:33:16 +0000126object as necessary. The default encoding is base64. See the
Barry Warsaw40ef0062006-03-18 15:41:53 +0000127\refmodule{email.encoders} module for a list of the built-in encoders.
Barry Warsaw5b9da892002-10-01 01:05:52 +0000128
129\var{_params} are passed straight through to the base class constructor.
130\end{classdesc}
131
132\begin{classdesc}{MIMEImage}{_imagedata\optional{, _subtype\optional{,
133 _encoder\optional{, **_params}}}}
Barry Warsaw40ef0062006-03-18 15:41:53 +0000134Module: \module{email.mime.image}
Barry Warsaw5b9da892002-10-01 01:05:52 +0000135
136A subclass of \class{MIMENonMultipart}, the \class{MIMEImage} class is
137used to create MIME message objects of major type \mimetype{image}.
138\var{_imagedata} is a string containing the raw image data. If this
139data can be decoded by the standard Python module \refmodule{imghdr},
140then the subtype will be automatically included in the
141\mailheader{Content-Type} header. Otherwise you can explicitly specify the
142image subtype via the \var{_subtype} parameter. If the minor type could
143not be guessed and \var{_subtype} was not given, then \exception{TypeError}
144is raised.
145
146Optional \var{_encoder} is a callable (i.e. function) which will
147perform the actual encoding of the image data for transport. This
148callable takes one argument, which is the \class{MIMEImage} instance.
149It should use \method{get_payload()} and \method{set_payload()} to
150change the payload to encoded form. It should also add any
151\mailheader{Content-Transfer-Encoding} or other headers to the message
Barry Warsaw5db478f2002-10-01 04:33:16 +0000152object as necessary. The default encoding is base64. See the
Barry Warsaw40ef0062006-03-18 15:41:53 +0000153\refmodule{email.encoders} module for a list of the built-in encoders.
Barry Warsaw5b9da892002-10-01 01:05:52 +0000154
155\var{_params} are passed straight through to the \class{MIMEBase}
156constructor.
157\end{classdesc}
158
159\begin{classdesc}{MIMEMessage}{_msg\optional{, _subtype}}
Barry Warsaw40ef0062006-03-18 15:41:53 +0000160Module: \module{email.mime.message}
161
Barry Warsaw5b9da892002-10-01 01:05:52 +0000162A subclass of \class{MIMENonMultipart}, the \class{MIMEMessage} class
163is used to create MIME objects of main type \mimetype{message}.
164\var{_msg} is used as the payload, and must be an instance of class
165\class{Message} (or a subclass thereof), otherwise a
166\exception{TypeError} is raised.
167
168Optional \var{_subtype} sets the subtype of the message; it defaults
169to \mimetype{rfc822}.
170\end{classdesc}
171
Barry Warsawbb113862004-10-03 03:16:19 +0000172\begin{classdesc}{MIMEText}{_text\optional{, _subtype\optional{, _charset}}}
Barry Warsaw40ef0062006-03-18 15:41:53 +0000173Module: \module{email.mime.text}
174
Barry Warsaw5b9da892002-10-01 01:05:52 +0000175A subclass of \class{MIMENonMultipart}, the \class{MIMEText} class is
176used to create MIME objects of major type \mimetype{text}.
177\var{_text} is the string for the payload. \var{_subtype} is the
178minor type and defaults to \mimetype{plain}. \var{_charset} is the
179character set of the text and is passed as a parameter to the
180\class{MIMENonMultipart} constructor; it defaults to \code{us-ascii}. No
Barry Warsawa996d4f2003-03-11 05:03:25 +0000181guessing or encoding is performed on the text data.
Barry Warsaw5b9da892002-10-01 01:05:52 +0000182
Barry Warsawbb113862004-10-03 03:16:19 +0000183\versionchanged[The previously deprecated \var{_encoding} argument has
184been removed. Encoding happens implicitly based on the \var{_charset}
185argument]{2.4}
Barry Warsaw5b9da892002-10-01 01:05:52 +0000186\end{classdesc}