{"id":23879,"library":"imaplib2","title":"imaplib2","description":"imaplib2 is a threaded Python IMAP4 client library, compatible with Python 3.6+. Version 3.6 is the latest stable release. It is maintained by the Jazzband community and provides an alternative to the standard library's imaplib, with threading support and improved performance.","status":"active","version":"3.6","language":"python","source_language":"en","source_url":"https://github.com/jazzband/imaplib2","tags":["IMAP","email","threaded","client","imaplib"],"install":[{"cmd":"pip install imaplib2","lang":"bash","label":"Install imaplib2"}],"dependencies":[],"imports":[{"note":"Direct import of imaplib2 without using submodule will not expose IMAP4 class.","wrong":"import imaplib2","symbol":"IMAP4","correct":"from imaplib2 import IMAP4"}],"quickstart":{"code":"import os\nfrom imaplib2 import IMAP4\n\nwith IMAP4('imap.example.com') as M:\n    M.login(os.environ['USER'], os.environ['PASS'])\n    M.select()\n    typ, data = M.search(None, 'ALL')\n    print(data)","lang":"python","description":"Connect to an IMAP server, login, select inbox, and search for all messages."},"warnings":[{"fix":"Replace `keyfile` and `certfile` arguments with `ssl.SSLContext` object passed to `IMAP4_SSL`.","message":"imaplib2 3.x drops support for SSL/TLS context parameters like `keyfile` and `certfile`. Use `ssl_context` instead.","severity":"deprecated","affected_versions":">=3.0"},{"fix":"Use `IMAP4_SSL` for SSL connections, not `IMAP4`.","message":"In version 3.x, the `IMAP4` class no longer supports direct SSL without using `IMAP4_SSL`. Plain `IMAP4` is for non-SSL connections only.","severity":"breaking","affected_versions":">=3.0"},{"fix":"Avoid forking after establishing an IMAP session. Reconnect in child processes if needed.","message":"The library is thread-safe but not fork-safe. Using `os.fork()` after creating an IMAP connection may lead to undefined behavior.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from imaplib2 import IMAP4` or `import imaplib2; imaplib2.IMAP4` (imaplib2 exposes IMAP4 as alias).","cause":"Import statement is `import imaplib2` but the class is in submodules.","error":"AttributeError: module 'imaplib2' has no attribute 'IMAP4'"},{"fix":"Ensure you call `login()` or `authenticate()` before any mailbox commands.","cause":"Trying to execute commands before login or after logout.","error":"imaplib2.IMAP4.error: command SEARCH illegal in state NONAUTH"},{"fix":"Implement reconnect logic. Use try/except and re-instantiate connection.","cause":"Server timeout or network issue; library raises abort on connection loss.","error":"imaplib2.IMAP4.abort: connection closed unexpectedly"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}