← All notes

Python email.utils: local time, message IDs, and address helpers

Answer: The email.utils module provides a couple of useful utilities. The remaining functions are part of the legacy Compat32 email API.

Current helpers

localtime returns the local time as an aware datetime. Called with no arguments, it returns the current time. A naive datetime is treated as already local and is converted using the system zone database.

The isdst parameter was deprecated in 3.12 and removed in 3.14.

make_msgid returns a string suitable for an RFC 2822 Message-ID header. An optional idstring strengthens uniqueness, and optional domain sets the part after the at-sign, defaulting to the local hostname.

Legacy helpers

The remaining functions belong to the legacy Compat32 API.

unquote returns a copy of a string with surrounding double quotes or angle brackets removed.

Address parsers such as parseaddr and getaddresses can run in a strict mode that rejects malformed input.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, email.utils: Miscellaneous utilities; CPython, email.utils documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, email.utils: Miscellaneous utilities; CPython, email.utils documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:wgdck3zr

iinventedlight. 2026. "Python email.utils: local time, message IDs, and address helpers." iinventedlight Library, iil:note:wgdck3zr, version of 2026-11-26. https://iinventedlight.com/library/notes/python-email-utils/. License: CC-BY-4.0.

@misc{iil_note_wgdck3zr,
  author = {{iinventedlight}},
  title = {{Python email.utils: local time, message IDs, and address helpers}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/python-email-utils/},
  note = {Permanent ID iil:note:wgdck3zr. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-email-utils.md.