Python imaplib: an IMAP4 protocol client
Answer: This module defines three classes, IMAP4, IMAP4_SSL and IMAP4_stream.
Classes and protocol
The three classes are IMAP4, IMAP4_SSL, and IMAP4_stream.
Together they encapsulate a connection to an IMAP4 server.
The implemented subset follows the IMAP4rev1 client protocol in RFC 3501.
It is backward compatible with IMAP4 (RFC 1730) servers.
The STATUS command is not supported in plain IMAP4.
The module is not available on WebAssembly.
Connection defaults and context managers
When host is omitted, the local host is used.
When port is omitted, the standard IMAP4 port 143 is used.
The IMAP4 class can be used as a context manager.
The IMAP4 LOGOUT command is issued automatically when the with statement exits.
See also
Claims
- id: C1 claim: The module defines IMAP4, IMAP4_SSL, and IMAP4_stream. source: S1 evidence: "three classes, IMAP4 , IMAP4_SSL and IMAP4_stream"
- id: C2 claim: The client covers a large subset of IMAP4rev1 in RFC 3501. source: S1 evidence: "large subset of the IMAP4rev1 client protocol as defined in RFC 3501"
- id: C3 claim: The STATUS command is not supported in IMAP4. source: S2 evidence: "command is not supported in IMAP4"
- id: C4 claim: Leaving a with block issues LOGOUT automatically. source: S2 evidence: "command is issued automatically"
Sources
- [S1] imaplib — IMAP4 protocol client. Python Software Foundation. https://docs.python.org/3/library/imaplib.html . License: PSF License Version 2. Accessed 2026-11-23.
- [S2] imaplib documentation (source). CPython. https://raw.githubusercontent.com/python/cpython/main/Doc/library/imaplib.rst . License: PSF License Version 2. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, imaplib — IMAP4 protocol client; CPython, imaplib 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, imaplib — IMAP4 protocol client; CPython, imaplib documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.
Cite this
iinventedlight. 2026. "Python imaplib: an IMAP4 protocol client." iinventedlight Library, iil:note:g8pqxacv, version of 2026-11-23. https://iinventedlight.com/library/notes/python-imaplib/. License: CC-BY-4.0.
@misc{iil_note_g8pqxacv,
author = {{iinventedlight}},
title = {{Python imaplib: an IMAP4 protocol client}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/python-imaplib/},
note = {Permanent ID iil:note:g8pqxacv. License: CC-BY-4.0.},
}
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.
- python-imaplib.schema.json (schema; CC-BY-4.0)
- python-imaplib.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-imaplib.md.