email.contentmanager.raw_data_manager
This content manager provides only a minimum interface beyond that provided by Message itself: it deals only with text, raw byte strings, and Message objects. Nevertheless, it provides significant advantages compared to the base API: get_content on a text part will return a unicode string without the application needing to manually decode it, set_content provides a rich set of options for controlling the headers added to a part and controlling the content transfer encoding, and it enables the use of the various add_ methods, thereby simplifying the creation of multipart messages.
-
email.contentmanager.get_content(msg, errors='replace') -
Return the payload of the part as either a string (for
textparts), anEmailMessageobject (formessage/rfc822parts), or abytesobject (for all other non-multipart types). Raise aKeyErrorif called on amultipart. If the part is atextpart and errors is specified, use it as the error handler when decoding the payload to unicode. The default error handler isreplace.
-
email.contentmanager.set_content(msg, , subtype="plain", charset='utf-8' cte=None, disposition=None, filename=None, cid=None, params=None, headers=None) -
email.contentmanager.set_content(msg, , maintype, subtype, cte="base64", disposition=None, filename=None, cid=None, params=None, headers=None) -
email.contentmanager.set_content(msg, , cte=None, disposition=None, filename=None, cid=None, params=None, headers=None) -
email.contentmanager.set_content(msg, , subtype='mixed', disposition=None, filename=None, cid=None, params=None, headers=None) -
Add headers and payload to msg:
Add a Content-Type header with a
maintype/subtypevalue.- For
str, set the MIMEmaintypetotext, and set the subtype to subtype if it is specified, orplainif it is not. - For
bytes, use the specified maintype and subtype, or raise aTypeErrorif they are not specified. - For
Messageobjects, set the maintype tomessage, and set the subtype to subtype if it is specified orrfc822if it is not. If subtype ispartial, raise an error (bytesobjects must be used to constructmessage/partialparts). - For <’list’>, which should be a list of
Messageobjects, set themaintypetomultipart, and thesubtypeto subtype if it is specified, andmixedif it is not. If the message parts in the <’list’> have MIME-Version headers, remove them.
If charset is provided (which is valid only for
str), encode the string to bytes using the specified character set. The default isutf-8. If the specified charset is a known alias for a standard MIME charset name, use the standard charset instead.If cte is set, encode the payload using the specified content transfer encoding, and set the Content-Transfer-Endcoding header to that value. For
strobjects, if it is not set use heuristics to determine the most compact encoding. Possible values for cte arequoted-printable,base64,7bit,8bit, andbinary. If the input cannot be encoded in the specified encoding (eg:7bit), raise aValueError. ForMessage, per RFC 2046, raise an error if a cte ofquoted-printableorbase64is requested for subtyperfc822, and for any cte other than7bitfor subtypeexternal-body. Formessage/rfc822, use8bitif cte is not specified. For all other values of subtype, use7bit.Note
A cte of
binarydoes not actually work correctly yet. TheMessageobject as modified byset_contentis correct, butBytesGeneratordoes not serialize it correctly.If disposition is set, use it as the value of the Content-Disposition header. If not specified, and filename is specified, add the header with the value
attachment. If it is not specified and filename is also not specified, do not add the header. The only valid values for disposition areattachmentandinline.If filename is specified, use it as the value of the
filenameparameter of the Content-Disposition header. There is no default.If cid is specified, add a Content-ID header with cid as its value.
If params is specified, iterate its
itemsmethod and use the resulting(key, value)pairs to set additional parameters on the Content-Type header.If headers is specified and is a list of strings of the form
headername: headervalueor a list ofheaderobjects (distinguised from strings by having anameattribute), add the headers to msg. - For
Please login to continue.