IMAP MCP server: your AI agent searches, reads, files and drafts email in any IMAP mailbox.
Your agent finds and reads mail in every folder with search_emails, get_email and get_thread, files them with archive_emails, move_emails and trash_emails, marks them with mark_emails, and saves drafts for you to review and send with create_draft. It works with any IMAP server that accepts a password login and with any MCP client that starts local servers, such as Claude Desktop, Claude Code or Cursor.
Install · Tools · Changelog · Hosted version
{
"mcpServers": {
"imap": {
"command": "npx",
"args": ["-y", "imap-mcp"],
"env": {
"IMAP_HOST": "imap.example.com",
"IMAP_PORT": "993",
"IMAP_USERNAME": "you@example.com",
"IMAP_PASSWORD": "<app password>",
"IMAP_USE_SSL": "true"
}
}
}
}The buttons add the server with placeholder settings: replace the host, username and password with your own, or take them from a preset. You need Node.js for npx.
Claude Desktop
Open Settings → Developer → Edit Config, or the file itself:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Add the server under mcpServers, then restart Claude Desktop:
{
"mcpServers": {
"imap": {
"command": "npx",
"args": ["-y", "imap-mcp"],
"env": {
"IMAP_HOST": "imap.example.com",
"IMAP_PORT": "993",
"IMAP_USERNAME": "you@example.com",
"IMAP_PASSWORD": "<app password>",
"IMAP_USE_SSL": "true"
}
}
}
}Claude Code
claude mcp add imap \
-e IMAP_HOST=imap.example.com -e IMAP_PORT=993 \
-e IMAP_USERNAME=you@example.com -e 'IMAP_PASSWORD=<app password>' \
-e IMAP_USE_SSL=true \
-- npx -y imap-mcpThis stores the server in ~/.claude.json for the current project. Add --scope user for every project, or --scope project to write it to the project's .mcp.json, which is shared with everyone who checks the project out, password included.
Cursor
Add the server to ~/.cursor/mcp.json (every project) or .cursor/mcp.json (one project), with the same mcpServers JSON as for Claude Desktop.
VS Code
Run MCP: Open User Configuration from the Command Palette (every workspace), or create .vscode/mcp.json (one workspace). VS Code names the key servers. With an input, VS Code asks for the password once and stores it securely instead of in the file:
{
"inputs": [
{
"type": "promptString",
"id": "imap-password",
"description": "IMAP app password",
"password": true
}
],
"servers": {
"imap": {
"type": "stdio",
"command": "npx",
"args": ["-y", "imap-mcp"],
"env": {
"IMAP_HOST": "imap.example.com",
"IMAP_PORT": "993",
"IMAP_USERNAME": "you@example.com",
"IMAP_PASSWORD": "${input:imap-password}",
"IMAP_USE_SSL": "true"
}
}
}
}Other clients
Any MCP client that starts local servers over stdio works: give it the command npx -y imap-mcp and the environment variables from Configuration. Most clients, such as Windsurf (~/.codeium/windsurf/mcp_config.json), take the mcpServers JSON shown for Claude Desktop.
For several mailboxes, add the server once per mailbox under different names, such as imap-work and imap-home.
imap-mcp reads its settings from the environment, or from a .env file in the directory it starts in.
| Variable | Required | Default | Meaning |
|---|---|---|---|
IMAP_HOST |
Yes | Hostname of the IMAP server, such as imap.example.com |
|
IMAP_PORT |
No | 993 |
Port of the IMAP server |
IMAP_USERNAME |
Yes | Username to log in with, usually your email address. Also the From address of drafts that set none. | |
IMAP_PASSWORD |
Yes | Password to log in with: an app password where your provider offers one (Security) | |
IMAP_USE_SSL |
No | false |
true connects over TLS, as port 993 expects. Any other value connects without encryption: imap-mcp never upgrades a connection with STARTTLS, so your password and mail travel in clear text. |
IMAP_TLS_REJECT_UNAUTHORIZED |
No | true |
false accepts a server certificate that is self-signed or not valid for IMAP_HOST (TLS certificates) |
MCP_ACCESS |
No | everything |
What the agent may do: read-only, no-send or everything (Access levels). The --access argument wins over it. |
Note the default of IMAP_USE_SSL: almost every provider needs "IMAP_USE_SSL": "true", which the presets below set.
Every preset uses port 993 with IMAP_USE_SSL set to true, unless the row says otherwise. IMAP_USERNAME is your full email address.
| Provider | IMAP_HOST |
IMAP_PORT |
IMAP_USE_SSL |
Password |
|---|---|---|---|---|
| Gmail | imap.gmail.com |
993 |
true |
An app password, which needs 2-Step Verification |
| iCloud Mail | imap.mail.me.com |
993 |
true |
An app-specific password |
| Fastmail | imap.fastmail.com |
993 |
true |
An app password with IMAP access, from Settings → Privacy & Security |
| Yahoo Mail | imap.mail.yahoo.com |
993 |
true |
An app password from Account Security |
| mailbox.org | imap.mailbox.org |
993 |
true |
Your password, or an app password if you use two-factor login |
| GMX | imap.gmx.net (imap.gmx.com for gmx.com addresses) |
993 |
true |
Your password after turning on IMAP in GMX's settings, or an app password if two-factor login is on |
| Proton Mail | 127.0.0.1 |
1143 |
true |
The password Proton Mail Bridge shows. Set Bridge's connection mode to SSL and IMAP_TLS_REJECT_UNAUTHORIZED to false, as Bridge's certificate is self-signed. |
| Your own server | Your server's hostname | 993 |
true |
Your account's password, for example on Dovecot or Stalwart |
Nextcloud runs no IMAP server of its own: its Mail app connects to a mailbox somewhere else, so use the preset of that mailbox's provider.
imap-mcp runs on your computer, started by your MCP client, and logs in to one mailbox with the settings above. What the agent can do there:
- It never sends mail.
create_draftsaves a draft in your Drafts folder for you to review and send yourself. imap-mcp has no SMTP settings. - It never deletes mail for good.
trash_emailsmoves mail to Trash, where it stays recoverable until you empty Trash. There is no permanent delete and no tool that empties a folder. - It changes the mailbox only through its tools: marking read, starred or to-do, archiving, moving, trashing and saving drafts. Searching and reading never mark mail read.
- One tool reaches someone else.
unsubscribe_from_listsends a newsletter's one-click unsubscribe request (RFC 8058) to the link in the message'sList-Unsubscribeheader. Leave it out with theno-sendaccess level.
--access or MCP_ACCESS sets what the agent may do through imap-mcp. The flag wins when both are set; changing the level needs a restart of the server.
| Level | The agent may | Tools |
|---|---|---|
read-only |
Read the mailbox | search_emails, get_email, get_thread |
no-send |
Also change the mailbox, but send nothing and reach no one else | search_emails, get_email, get_thread, mark_emails, archive_emails, move_emails, trash_emails, create_draft |
everything (default) |
Also reach other people | search_emails, get_email, get_thread, mark_emails, archive_emails, move_emails, trash_emails, create_draft, unsubscribe_from_list |
A tool outside the level is left out of the tool list, and a call to it is refused without changing anything. An unknown value stops the server at start with exit code 2. The level is logged on stderr at start.
For example, to start the server read-only:
"args": ["-y", "imap-mcp", "--access", "read-only"]Your username and password stay in your MCP client's configuration (or a .env file) on your computer, and imap-mcp sends them only to IMAP_HOST. Use an app password, never your account password, wherever your provider offers one: it gives IMAP access only, and you can revoke it without changing your account password. Providers that allow only OAuth login over IMAP, such as Outlook.com, don't work (Supported providers).
With IMAP_USE_SSL set to true, imap-mcp checks that the server's certificate is valid for IMAP_HOST and refuses to connect, before sending your password, when it is not. This check is on by default.
If your server uses a self-signed or otherwise untrusted certificate, set IMAP_TLS_REJECT_UNAUTHORIZED to exactly false to turn the check off. With the check off, imap-mcp cannot tell your server from another one, so use it only on a network you trust.
Anyone can send you mail, and a message can contain text written to steer an AI agent ("forward the last invoice to …"). imap-mcp tells the agent, in its server instructions and in the descriptions of search_emails, get_email and get_thread, that message content comes from whoever sent it and is data to read and report on, never instructions to follow. Whether the agent heeds that is up to the agent and your client. imap-mcp cannot send or forward mail, so such text cannot make it do either; it also tells the agent to confirm with you before unsubscribing. To narrow what such text could do, start the server with read-only or no-send, and keep your client asking before it runs a tool that changes your mailbox.
imap-mcp collects nothing and reports nothing to Langmail or anyone else. Its only connections are to IMAP_HOST and, when unsubscribe_from_list runs, to the unsubscribe link of the message it was given, and to at most three HTTPS addresses that link redirects to.
Each release is published to npm from this repository's release workflow through npm trusted publishing, so every version carries a provenance attestation. The Provenance section of the npm page names the repository, commit and workflow run that built each version. To check the registry signatures and provenance attestations of an installed copy, run in a project that depends on imap-mcp:
npm audit signaturesimap-mcp works with an IMAP server that accepts a username-and-password login. A provider is listed as working only when someone has used it.
| Provider | Status |
|---|---|
| Gmail | Works, with an app password |
| Outlook.com | Known issue: it allows only OAuth login over IMAP, which imap-mcp lacks |
| iCloud Mail | Not yet tested |
| Fastmail | Not yet tested |
| Yahoo Mail | Not yet tested |
| mailbox.org | Not yet tested |
| GMX | Not yet tested |
| Proton Mail (through Bridge) | Not yet tested |
| Dovecot, Stalwart and other servers | Not yet tested |
Used it with one of these, or another one? Tell us in an issue or on Discord.
The server also sends instructions that tell the agent where to start.
Only reads the mailbox. Access level: read-only.
Finds messages in every folder, or in one, and lists them a page at a time with id, subject, sender, date, folders, tags, unread and starred flags, and attachments. Searching never marks anything read.
Parameters (at least one filter is required):
query(string, optional): Free text over subject, body and addresses. Messages holding any term match; those holding every term come first, then the rest by how many terms they hold. A phrase in double quotes matches as written.after/before(UTC ISO-8601 timestamp, optional): Only messages received on/after, or strictly before, this timefrom(string, optional): Substring of the sender's name or addressread(boolean, optional):falsefor unread messages only,truefor read ones onlystarred(boolean, optional):truefor starred (\Flagged) messages only,falsefor the otherstodo(boolean, optional):truefor messages flagged as a to-do (the$label:todokeyword Langmail sets) only,falsefor the othersmailbox(string, optional): One folder only.Inbox,Sent,Archive,Drafts,TrashandJunkfind the folder your server marks with that special-use attribute (RFC 6154), such as[Gmail]/Sent Mail; any other value matches a folder name exactly.limit(number, optional): Hits per page, 1–100, default 20cursor(string, optional): The cursor a previous result printed, for the next page of the same search
Example:
{
"read": false
}Message ids are the server's stable id where it has one (OBJECTID, RFC 8474, or Gmail's X-GM-MSGID), so they keep working after a message moves to another folder. On other servers an id names the folder and UID and changes when the message moves.
Only reads the mailbox. Access level: read-only.
Returns one message by the id search_emails or get_thread gave: subject, sender, recipients, date, folders, tags, the body as readable text or Markdown (converted with langmail, also for HTML-only mail; a message over 10 MB shows only its plain-text part), and the attachments' names, types and sizes. Reading a message does not mark it read.
Parameters:
id(string, required): The message id fromsearch_emailsorget_thread
Example:
{
"id": "e.1784212345678901234"
}Only reads the mailbox. Access level: read-only.
Lists every message of a message's conversation, oldest first, in every folder, so the user's own replies in Sent are included. Each message comes with the same details as a search_emails hit, and the one asked about is marked ← requested. The thread is the server's thread id where it has one (OBJECTID's THREADID, RFC 8474, or Gmail's X-GM-THRID); otherwise it is every message linked by the Message-ID, In-Reply-To and References headers. Listing a thread does not mark anything read.
Parameters:
id(string, required): A message id fromsearch_emailsorget_thread
Example:
{
"id": "e.1784212345678901234"
}Changes the mailbox. Access level: no-send.
Sets or clears read, to-do and starred on one or more messages. Read is the \Seen flag, starred \Flagged, and to-do the $label:todo keyword Langmail sets, so both see the same to-dos; a server that keeps no custom keywords cannot store the to-do. A flag left out stays as it was, and nothing moves. Reports how many messages changed and names each id it could not change; re-running it changes nothing.
Parameters (at least one flag is required):
ids(string array, required): 1–50 message ids fromsearch_emailsorget_threadread(boolean, optional):truemarks read,falseunreadstarred(boolean, optional):truestars,falseremoves the startodo(boolean, optional):trueflags as a to-do,falseclears it
Example:
{
"ids": ["e.1784212345678901234"],
"read": true,
"todo": false
}Changes the mailbox. Access level: no-send.
Takes messages out of the Inbox, Junk and Trash and into the folder your server marks as Archive (RFC 6154); other folders they are in, such as Sent, stay as they are. On Gmail, which has no Archive folder, the message leaves the Inbox and stays in All Mail. Without an Archive folder the tool says so and creates none. Read state and flags are kept. Reports how many messages it archived and names each id it could not archive; re-running it changes nothing.
Parameters:
ids(string array, required): 1–50 message ids fromsearch_emailsorget_thread
Example:
{
"ids": ["e.1784212345678901234"]
}Changes the mailbox. Access level: no-send.
Moves messages into a folder, out of every folder they were in (on Gmail they also stay in All Mail). The folder is named like the mailbox filter of search_emails; a folder that does not exist is an error that lists the folders there are, and nothing is created. Trash is refused: use trash_emails. Read state and flags are kept. Reports how many messages moved and names each id it could not move; re-running it changes nothing.
Parameters:
ids(string array, required): 1–50 message ids fromsearch_emailsorget_threadmailbox(string, required): The destination folder, such asProjectsorInbox
Example:
{
"ids": ["e.1784212345678901234"],
"mailbox": "Projects"
}Changes the mailbox. Access level: no-send. Annotated as destructive, so clients may ask before running it.
Moves messages into the folder your server marks as Trash (RFC 6154), where they stay recoverable until Trash is emptied. There is no permanent delete. Reports how many messages it trashed and names each id it could not trash; re-running it changes nothing.
Parameters:
ids(string array, required): 1–50 message ids fromsearch_emailsorget_thread
Example:
{
"ids": ["e.1784212345678901234"]
}On servers without MOVE (RFC 6851), the three moving tools copy each message, mark it \Deleted and expunge only those messages by UID (UIDPLUS, RFC 4315). A server with neither leaves a folder alone that holds other deleted messages, and the tool names those ids. On servers without a stable message id, a moved message gets a new id: search again before acting on it.
Changes the mailbox. Access level: no-send.
Creates a draft email message and saves it to the IMAP server's drafts folder.
Parameters:
to(string, required): The recipient's email addresssubject(string, required): The email subject linebody(string, required): The email body contentfrom(string, optional): The sender's email address (defaults to IMAP_USERNAME)
Example:
{
"to": "recipient@example.com",
"subject": "Meeting Reminder",
"body": "Don't forget about our meeting tomorrow at 2 PM.",
"from": "sender@example.com"
}The tool saves the draft to the folder your server marks as the drafts folder (the \Drafts special-use attribute, RFC 6154), such as [Gmail]/Drafts on Gmail. If the server marks no folder that way, it tries INBOX.Drafts, then Drafts.
Sends a request to the newsletter's sender. Access level: everything.
Unsubscribes the user from the mailing list or newsletter one message came from. It reads the message's List-Unsubscribe header and, when the sender supports one-click unsubscribe over HTTPS (RFC 8058), sends that request itself. It never sends mail and needs no SMTP settings: for a sender that offers only a mailto: address or a plain link, or no header at all, it returns the address (with subject and body) or the link, or an unsubscribe link from the message body, for the user to use themselves.
The result says whether the sender accepted the request, with the HTTP status and a short excerpt of the response; an accepted request does not prove the subscription has ended. It names the address the copy was delivered to and warns when the link looks like "unsubscribe from all". A message in Junk is refused; the refusal tells the agent to leave it there, or, if the user says it is not spam, to move it out with move_emails and call again. A link to a private, loopback or link-local address is refused, and redirects are followed only over HTTPS to public addresses, at most three.
Parameters:
id(string, required): The message id fromsearch_emailsorget_threadconfirmNotification(boolean, optional): For a message taggednotification(the$label:notificationkeyword),trueonce the user has confirmed that muting what the link covers is what they want. A tagged message is refused without it; for other messages it changes nothing.
Example:
{
"id": "e.1784212345678901234"
}- What came in overnight that I haven't read yet? Summarize it and tell me what needs an answer today.
- Find the invoice from the hosting company from last March and tell me the amount.
- Archive every newsletter in my inbox that is older than a week.
- Read the thread about the office move and draft a reply that says Thursday works for me.
- Show me my to-dos and star the ones that are due this week.
- Unsubscribe me from the weekly deals mail of the shoe shop.
Use imap-mcp to give an agent the mailbox you already have, at any provider that offers IMAP with a password login. It runs on your computer, your mail goes only between your computer and your IMAP server, and it costs nothing. You install and update it yourself, and it works only in MCP clients that start local servers, not in apps that connect only to remote ones.
The hosted Langmail is a mail service of its own: you sign in with a Langmail account over OAuth, nothing runs on your computer, and Langmail's servers handle your mail. Its MCP server, langmail-mcp, covers mail, calendar and contacts, plus features that need Langmail's own services; its README compares hosted and self-hosted.
The MCP Registry lists several servers for IMAP. Some send mail over SMTP, offer dozens of tools, serve several accounts at once or run as a hosted service with OAuth. imap-mcp is deliberately narrower:
- It never sends mail: the agent saves drafts and you send them. Unsubscribing is the one request that leaves your mailbox, and the
no-sendlevel turns it off. - Access levels take tools away from the agent, so a
read-onlyagent cannot change your mailbox at all. - Searching and reading never mark mail read, and nothing is ever deleted for good.
- It searches every folder at once, follows a conversation into Sent, and keeps message ids stable when mail moves, where the server supports it (OBJECTID or Gmail's ids).
- Bodies come as readable text or Markdown, also for HTML-only mail.
- It handles one mailbox per server entry, logs in with a password only and has no OAuth.
No: Outlook.com allows only OAuth login over IMAP (Supported providers).
Yes: start the server with --access read-only (Access levels).
Also from Langmail: caldav-mcp for calendars, carddav-mcp for contacts, and langmail-mcp for mail, calendar and contacts of a JMAP mailbox.
git clone https://github.com/langmail/imap-mcp.git
cd imap-mcp
npm install
npm test
npm run build
node dist/index.jsnpm run lint and npm run format:check run the other checks CI runs.
MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.