Email and MIME Modules

email

Constructs, parses and serializes email messages and MIME parts. The package represents message content as a tree; policy controls parsing and serialization. It does not deliver messages to servers; use a separate transport such as smtplib.

Formal Syntax & Structure

python syntaxpython
import email

Return Value

module

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

Working Example

Example Snippetpython
import emailfrom email import policymessage = email.message_from_bytes(b"Subject: Note\r\n\r\nHello", policy=policy.default)print(message["Subject"])
Python Reference