email.message_from_binary_file()

email.message_from_binary_file(fp, _class=email.message.Message, *, policy=policy.compat32) Return a message object structure tree from an open binary file object. This is exactly equivalent to BytesParser().parse(fp). _class and policy are interpreted as with the Parser class constructor. New in version 3.2. Changed in version 3.3: Removed the strict argument. Added the policy keyword.

email.message.Message.__setitem__()

__setitem__(name, val) Add a header to the message with field name name and value val. The field is appended to the end of the message’s existing fields. Note that this does not overwrite or delete any existing header with the same name. If you want to ensure that the new header is the only one present in the message with field name name, delete the field first, e.g.: del msg['subject'] msg['subject'] = 'Python roolz!'

email.message_from_bytes()

email.message_from_bytes(s, _class=email.message.Message, *, policy=policy.compat32) Return a message object structure from a byte string. This is exactly equivalent to BytesParser().parsebytes(s). Optional _class and strict are interpreted as with the Parser class constructor. New in version 3.2. Changed in version 3.3: Removed the strict argument. Added the policy keyword.

email.message.Message.__bytes__()

__bytes__() Equivalent to as_bytes(). Allows bytes(msg) to produce a bytes object containing the formatted message. New in version 3.4.

email.message.Message.walk()

walk() The walk() method is an all-purpose generator which can be used to iterate over all the parts and subparts of a message object tree, in depth-first traversal order. You will typically use walk() as the iterator in a for loop; each iteration returns the next subpart. Here’s an example that prints the MIME type of every part of a multipart message structure: >>> for part in msg.walk(): ... print(part.get_content_type()) multipart/report text/plain message/delivery-status te

email.message.Message.__getitem__()

__getitem__(name) Return the value of the named header field. name should not include the colon field separator. If the header is missing, None is returned; a KeyError is never raised. Note that if the named field appears more than once in the message’s headers, exactly which of those field values will be returned is undefined. Use the get_all() method to get the values of all the extant named headers.

email.message.Message.__contains__()

__contains__(name) Return true if the message object has a field named name. Matching is done case-insensitively and name should not include the trailing colon. Used for the in operator, e.g.: if 'message-id' in myMessage: print('Message-ID:', myMessage['message-id'])

email.message.Message.__delitem__()

__delitem__(name) Delete all occurrences of the field with name name from the message’s headers. No exception is raised if the named field isn’t present in the headers.

email.message.Message.__len__()

__len__() Return the total number of headers, including duplicates.

email.message.Message.set_unixfrom()

set_unixfrom(unixfrom) Set the message’s envelope header to unixfrom, which should be a string.