8000 GitHub - langmail/imap-mcp: IMAP MCP server: your AI agent searches, reads, files and drafts email in any IMAP mailbox. · GitHub
[go: up one dir, main page]

Skip to content
langmailPublic

About

IMAP MCP server: your AI agent searches, reads, files and drafts email in any IMAP mailbox.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

15 stars

Watchers

0 watching

Forks

Latest commit

 

History

83 Commits

Folders and files

Langmail

imap-mcp

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.

npm CI License

Join us on Discord

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"
      }
    }
  }
}

Install

Install in VS Code Install in Cursor

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-mcp

This 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.

Configuration

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.

Presets

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.

Security and permissions

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_draft saves 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_emails moves 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_list sends a newsletter's one-click unsubscribe request (RFC 8058) to the link in the message's List-Unsubscribe header. Leave it out with the no-send access level.

Access levels

--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"]

Credentials

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).

TLS certificates

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.

Mail is data, not instructions

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.

No telemetry

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.

Check the package

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 signatures

Supported providers

imap-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.

Available Tools

The server also sends instructions that tell the agent where to start.

search_emails

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 time
  • from (string, optional): Substring of the sender's name or address
  • read (boolean, optional): false for unread messages only, true for read ones only
  • starred (boolean, optional): true for starred (\Flagged) messages only, false for the others
  • todo (boolean, optional): true for messages flagged as a to-do (the $label:todo keyword Langmail sets) only, false for the others
  • mailbox (string, optional): One folder only. Inbox, Sent, Archive, Drafts, Trash and Junk find 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 20
  • cursor (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.

get_email

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 from search_emails or get_thread

Example:

{
  "id": "e.1784212345678901234"
}

get_thread

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 from search_emails or get_thread

Example:

{
  "id": "e.1784212345678901234"
}

mark_emails

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 from search_emails or get_thread
  • read (boolean, optional): true marks read, false unread
  • starred (boolean, optional): true stars, false removes the star
  • todo (boolean, optional): true flags as a to-do, false clears it

Example:

{
  "ids": ["e.1784212345678901234"],
  "read": true,
  "todo": false
}

archive_emails

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 from search_emails or get_thread

Example:

{
  "ids": ["e.1784212345678901234"]
}

move_emails

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 from search_emails or get_thread
  • mailbox (string, required): The destination folder, such as Projects or Inbox

Example:

{
  "ids": ["e.1784212345678901234"],
  "mailbox": "Projects"
}

trash_emails

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 from search_emails or get_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.

create_draft

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 address
  • subject (string, required): The email subject line
  • body (string, required): The email body content
  • from (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.

unsubscribe_from_list

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 from search_emails or get_thread
  • confirmNotification (boolean, optional): For a message tagged notification (the $label:notification keyword), true once 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"
}

Example prompts

  • 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.

FAQ

Should I use imap-mcp or the hosted Langmail?

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.

How does imap-mcp differ from the other IMAP MCP servers?

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-send level turns it off.
  • Access levels take tools away from the agent, so a read-only agent 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.

Does it work with Outlook.com?

No: Outlook.com allows only OAuth login over IMAP (Supported providers).

Can the agent read my mail without changing it?

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.

Development

git clone https://github.com/langmail/imap-mcp.git
cd imap-mcp
npm install
npm test
npm run build
node dist/index.js

npm run lint and npm run format:check run the other checks CI runs.

License

MIT OR Apache-2.0, at your option. See LICENSE-MIT and LICENSE-APACHE.

About

IMAP MCP server: your AI agent searches, reads, files and drafts email in any IMAP mailbox.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

15 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0