Email and MIME Modules

email.mime.message

Wraps an existing legacy Message object as an embedded message/rfc822 MIME part by default. The contained message is represented as a child object rather than flattened plain text. This wrapper cannot accept arbitrary additional attachments through attach.

Formal Syntax & Structure

python syntaxpython
import email.mime.message

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from email.message import Messagefrom email.mime.message import MIMEMessageinner = Message()inner["Subject"] = "Note"part = MIMEMessage(inner)print(part.get_content_type(), part.get_payload(0)["Subject"])
Python Reference