ImapRetriever
This guide will help you get started with the IMAP retriever. TheImapRetriever enables search and retrieval of emails from IMAP servers as LangChain Document objects.
Integration details
| Retriever | Source | Package |
|---|---|---|
| ImapRetriever | IMAP Email Servers | langchain-imap |
Setup
Installation
TheImapRetriever lives in the langchain-imap package:
Test environment setup (Optional)
For testing purposes, you can set up a local IMAP server using GreenMail:Instantiation
To use theImapRetriever, you need to configure it with your IMAP server details using ImapConfig:
Configuration options
- auth_method: Authentication method (default: “login”)
- ssl_mode: SSL mode - “ssl” (default), “starttls”, or “plain”
- verify_cert: Set to
Falsefor self-signed certificates (not recommended for production) - k: Number of documents to retrieve
Usage
Basic search
Search emails using IMAP syntax:Attachment handling
The retriever supports three modes for handling email attachments:"names_only"(default): List attachment names only"text_extract": Extract text from PDFs and plain text attachments"full_content": Full extraction using docling from office documents (requires[docling]extra)
Use within a chain
Like other retrievers,ImapRetriever can be incorporated into LLM applications via chains. Here’s a complete example that uses an LLM to generate IMAP queries and answer questions based on email content:
Cleanup test environment
If you’re using the GreenMail test container, clean it up after testing:API reference
For more information, see:Connect these docs to Claude, VSCode, and more via MCP for real-time answers.