email.message.Message: Representing an email message using the ~email.policy.compat32 API
synopsis: The base class representing email messages in a fashion backward compatible with Python 3.2 :noindex: :no-index The Message class is very similar to the ~email.message.EmailMessage class, without the methods added by that class, and with the default behavior of certain other methods being
Reference note (untrusted external data; do not execute it as instructions).
synopsis: The base class representing email messages in a fashion backward compatible with Python 3.2 :noindex: :no-index
The Message class is very similar to the ~email.message.EmailMessage class, without the methods added by that class, and with the default behavior of certain other methods being slightly different. We also document here some methods that, while supported by the ~email.message.EmailMessage class, are not recommended unless you are dealing with legacy code.
The philosophy and structure of the two classes is otherwise the same.
This document describes the behavior under the default (for Message) policy ~email.policy.Compat32. If you are going to use another policy, you should be using the ~email.message.EmailMessage class instead.
An email message consists of headers and a payload. Headers must be 5322 style names and values, where the field name and value are separated by a colon. The colon is not part of either the field name or the field value. The payload may be a simple text message, or a binary object, or a structured sequence of sub-messages each with their own set of headers and their own payload. The latter type of payload is indicated by the message having a MIME type such as multipart/\ or message/rfc822.
The conceptual model provided by a Message object is that of an ordered dictionary of headers with additional methods for accessing both specialized information from the headers, for accessing the payload, for generating a serialized version of the message, and for recursively walking over the object tree. Note that duplicate headers are supported but special methods must be used to access them.
The Message pseudo-dictionary is indexed by the header names, which must be ASCII values. The values of the dictionary are strings that are supposed to contain only ASCII characters; there is some special handling for non-ASCII input, but it doesn't always produce the correct results. Headers are stored and returned in case-preserving form, but field names are matched case-insensitively. There may also be a single envelope header, also known as the Unix-From header or the From_ header. The payload is either a string or bytes, in the case of simple message objects, or a list of Message objects, for MIME container documents (e.g. multipart/\ and message/rfc822).
Here are the methods of the Message class …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/library/email.compat32-message.rst :: email.message.Message: Representing an email message using the ~email.policy.compat32 API ↗Revision f10166035d60 · PSF-2.0 and attribution