
Imap Mcp Server
io.github.nikolausm由 GitHub 账号 nikolausm 发布v2.2.0更新于 Oct 24, 2026
IMAP/SMTP MCP server to search, read, organize, send, reply & forward email for AI assistants
概览
本地 IMAP/SMTP 服务器,让助手在一个或多个邮箱中搜索、阅读、整理、发送、回复和转发邮件。
- 可以做什么
- 添加、更新、列出、连接和移除 IMAP 账户,可配置 SMTP 与常见服务商预设
- 搜索、读取邮件和最近邮件,包括正文、会话线索和附件
- 标记已读或未读、加星、移动、删除和批量删除邮件
- 通过 SMTP 发送、回复、转发和撰写草稿,可设置默认密送和允许的发件身份
- 列出、创建和查看文件夹、未读数量、文件夹状态与自定义关键字
- 检查邮箱的垃圾邮件与域名统计
- 适用场景
- 适合让助手处理真实邮箱:按发件人、主题或日期查找邮件,汇总会话,归档或清理邮件,并撰写回复或转发,无需切换到邮件客户端。
- 运行要求
- 以本地 Node.js 进程运行(需 Node.js 22.12 或更高版本),可通过 npx 或本地构建启动。每个账户需要 IMAP 凭据(主机、端口、用户名、密码;Gmail、Yahoo 等需应用专用密码),发送邮件还需 SMTP 访问权限。账户保存在本地配置文件中,也可在启动时通过按账户命名的环境变量提供凭据。
安装
在 SourceWeft 中
- 打开 控制台中的 Imap Mcp Server,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
IMAP MCP Server
A powerful Model Context Protocol (MCP) server that provides seamless IMAP email integration with secure account management and connection pooling.
Features
- 🔐 Secure Account Management: Encrypted credential storage with AES-256 encryption
- 🚀 Connection Pooling: Efficient IMAP connection management
- 📧 Comprehensive Email Operations: Search, read, move, mark, delete, and bulk delete emails
- ✉️ Email Sending: Send, reply, and forward emails via SMTP
- 📁 Folder Management: List folders, check status, get unread counts
- 🔄 Multiple Account Support: Manage multiple IMAP accounts simultaneously
- 🛡️ Type-Safe: Built with TypeScript for reliability
- 🌐 Web-Based Setup Wizard: Easy account configuration with provider presets
- 📱 15+ Email Providers: Pre-configured settings for Gmail, Outlook, Yahoo, and more
- 🔗 Auto SMTP Configuration: Automatic SMTP settings based on IMAP provider
Installation
Requires Node.js 22.12 or newer. Node 18 and 20 have both reached end-of-life, and several of this package's dependencies no longer support them. Check yours with
node --version.
Run via npx (No Installation Required)
Once published to npm, you can run the server directly without cloning or building anything — npx downloads the prebuilt package and runs it:
This is the easiest way to use the server in an MCP client (see Configuration for ready-to-paste npx configs).
Quick Install (Recommended)
macOS/Linux:
Windows (PowerShell as Administrator):
Manual Installation
- Clone the repository:
- Install dependencies:
- Build the project:
Account Setup
Accounts are stored encrypted in ~/.imap-mcp/accounts.json. This file is shared by all run modes — whether you start the server via npx, a global install, or a local clone, they all read the same accounts. So you only need to set up your accounts once.
Setting Up Accounts in npx Mode
If you run the server via npx (no clone), you have two ways to add accounts:
Option A — Run the setup wizard directly via npx (no install needed):
This launches the same web-based wizard described below and writes to ~/.imap-mcp/accounts.json, which your npx-configured MCP server then picks up automatically.
Option B — Add accounts straight from your AI client:
Once the MCP server is configured, just ask your assistant to add an account — it uses the imap_add_account tool. For example:
"Add my IMAP account: host imap.gmail.com, port 993, user [email protected], password …"
No separate setup step required.
Web-Based Setup Wizard (Recommended)
After installation, run the setup wizard:
Or if installed globally:
Or directly via npx without installing:
This will:
- Start a local web server
- Open your browser to the setup wizard
- Guide you through adding email accounts with pre-configured settings
The wizard listens on 127.0.0.1 only, so nothing else on your network can
reach it.
Running the wizard on another machine (server, NAS, VM)
Recommended: SSH tunnel. The wizard stays on loopback, and the connection is encrypted:
Open http://localhost:3000 in your local browser.
Alternative: bind to the network. Pass --host (or set IMAP_MCP_BIND):
The wizard then requires an access token and prints a URL containing it, e.g.
http://my-server:3000/?token=…. Open that URL; the token is exchanged for a
session cookie and removed from the address bar. Requests without the token are
refused, and so are cross-origin requests. Scripts can send
Authorization: Bearer <token> instead. To use a fixed token rather than a
random one per start, set IMAP_MCP_WIZARD_TOKEN (at least 16 characters); it is then not printed.
The connection is plain HTTP, so anyone who can read your network traffic can see the token and the passwords you enter. Use this only on networks you trust, and prefer the SSH tunnel otherwise.
Overriding Credentials via Environment Variables
You can override the username and password of an already-configured account at
runtime with environment variables — useful when you inject secrets from a
password manager or CI system instead of storing them in accounts.json.
The variables are keyed by the account name, uppercased with every
non-alphanumeric character replaced by _. For an account named Work Gmail
(key WORK_GMAIL):
Notes:
- Overrides apply only to existing accounts; if no account's normalized name matches, the variable is ignored.
- They are applied in memory only — nothing is written back to
accounts.json, and the values are used as-is (not re-encrypted). - Variables are consumed at startup: on server start they are captured into
an AES-256-encrypted in-memory cache and removed from
process.env, so the plaintext secret does not linger in the environment (where it could leak to child processes or diagnostics). Set them before launching the server.
The setup wizard integrates with this: each credential field (IMAP password,
IMAP username, SMTP username, SMTP password) has a "Do not save to config; set
later using an environment variable" checkbox. When ticked, the value you enter
is still used to test the connection, but it is not written to accounts.json —
the wizard shows the exact variable name to export, and the account picks the
credential up from that variable at runtime.
- SMTP variables take effect only when the account already has an SMTP config.
- Each variable takes effect independently; set only the ones you need.
If the variable is missing, the account still holds the empty placeholder the wizard wrote. Rather than dialing out with a blank credential — which providers answer with a generic authentication failure that looks exactly like a wrong password — the server refuses the connection and names what to set:
Because the variables are read once at startup, setting one in an already-running shell has no effect until the server is restarted.
Supported Email Providers
The setup wizard includes pre-configured settings for:
- Gmail / Google Workspace
- Microsoft Outlook / Hotmail / Live
- Yahoo Mail
- Apple iCloud Mail
- GMX
- WEB.DE
- IONOS (1&1)
- ProtonMail (with Bridge)
- Fastmail
- Zoho Mail
- AOL Mail
- mailbox.org
- Posteo
- Custom IMAP servers
Configuration
Claude Code (CLI)
Option A — via npx (no clone/build needed)
This always runs the latest published version and requires no local build.
Option B — from a local clone
If you use Claude Code in the terminal, add the MCP server with a single command:
Step 1: Make sure you have built the project first (see Manual Installation).
Step 2: Run this command in your terminal:
Important: Replace
/absolute/path/to/imap-mcp-serverwith the actual path where you cloned the repository. For example:
Step 3: Verify it was added:
You should see imap in the list of configured MCP servers. That's it — the IMAP tools are now available in your Claude Code sessions.
Tip: If you want to remove the server later, run:
Claude Desktop (GUI App)
Add the IMAP MCP server to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Option A — via npx (recommended, no clone/build needed):
Option B — from a local clone:
Restricting tool access (read-only mode / allowlist)
By default all tools are exposed. You can restrict which tools the agent sees
using two environment variables (set them under the env key of your MCP
config). This is useful when you want to give an assistant read-only access
to a mailbox, or expose only a hand-picked subset of tools.
Example — read-only access:
Example — explicit allowlist:
The read-only subset is: imap_list_accounts, imap_connect, imap_disconnect,
imap_test_account, imap_search_emails, imap_get_email,
imap_get_latest_emails, imap_download_attachment, imap_find_thread_messages,
imap_find_email_by_message_id, imap_list_folders, imap_folder_status,
imap_get_unread_count, imap_check_spam, imap_domain_stats,
imap_list_spam_domains.
Usage
Once configured, the IMAP MCP server provides the following tools in Claude:
Choosing an account. For the email and folder tools,
accountIdis optional and backward-compatible. You may instead passaccountName, and if you only have a single account configured you can omit both — that account is used by default. With multiple accounts and no selector, the tool returns a clear error listing your options (imap_list_accounts).
Account Management
-
imap_add_account: Add a new IMAP account
-
imap_update_account: Update an existing account (fix SMTP settings, rename, etc.)
allowedFrom is an application-level guardrail, not a hard security boundary:
an agent with access to imap_update_account can change the allowed identities.
The SMTP server must enforce the actual sender authorization policy. Sender
mailbox addresses are matched case-insensitively; the supplied display name and
address casing are preserved in the outbound From header. This applies to
sending, drafts, replies, and forwards.
-
imap_list_accounts: List all configured accounts
-
imap_remove_account: Remove an account
-
imap_connect: Connect to an account
-
imap_disconnect: Disconnect from an account
Email Operations
-
imap_search_emails: Search for emails
With
searchAllFolders, results include afolderfield per message plusfoldersSearched, and any folder that failed to open is reported infoldersErrored(so a 0-result answer is never silently incomplete).includeBodyis honored in the single-folder path only. For a cross-folder sweep the lightweight header shape is preserved by design — pulling RFC822 source for every match across many folders would multiply bandwidth and parse cost. Follow up withimap_get_emailfor the specific uids whose bodies you need.On some servers a "flagged"/starred message carries a custom keyword (e.g. an Open-Xchange color label or Apple's
$MailFlagBit*) instead of, or in addition to, the\Flaggedsystem flag — after any flagged search, check each result'scustomKeywordsfield before concluding a message is or isn't flagged. -
imap_get_email: Get full email content
-
imap_get_latest_emails: Get recent emails
-
imap_mark_as_read/unread: Change email read status
-
imap_flag_email/unflag_email: Star/unstar an email (sets or clears the IMAP \Flagged system flag — shows as a "star" in Gmail and Apple Mail). Some servers/clients (Open-Xchange, Apple Mail) also set a separate custom keyword (e.g.
$cl_N,$MailFlagBit*) when flagging; unflag only clears\Flagged, so if a message still shows as flagged, checkcustomKeywordsviaimap_get_emailand clear it withimap_remove_keyword. -
imap_add_keyword/remove_keyword: Set or clear an arbitrary custom (non-system) IMAP keyword/label on an email, passed through verbatim (e.g. provider color labels like Open-Xchange's
$cl_1..$cl_10or Apple Mail's$MailFlagBit0..$MailFlagBit2, or any other custom keyword). Backslash-prefixed system flags (e.g.\Flagged,\Seen,\Deleted) are rejected — use the dedicated flag/read tools for those. Not every server permits custom-keyword changes (see the mailbox's PERMANENTFLAGS); if the server rejects or silently ignores the change, the call fails instead of reporting success. -
imap_delete_email: Delete an email
-
imap_move_email: Move an email from one folder to another
-
imap_find_thread_messages: Find inbox messages that belong to the same conversation threads as messages already sorted into another folder. Uses RFC 3501 HEADER search on In-Reply-To and References — works on any IMAP server.
-
imap_download_attachment: Download an email attachment (returns images inline, extracts text from PDFs, or saves to downloads directory)
-
imap_bulk_delete: Delete multiple emails at once with chunking and auto-reconnection
-
imap_bulk_delete_by_search: Search for emails matching criteria and delete them all
At least one concrete criterion (
from,to,subject,before, orsince) is required — a call with no criteria is refused, so it can never match and delete an entire folder. On servers whose SEARCH is broken (see Troubleshooting → Search returns nothing) this tool,imap_delete_spamandimap_delete_by_domainreturn an error instead of deleting from a client-side match. -
imap_send_email: Send a new email
Attachments are validated before SMTP is contacted. Invalid base64, unreadable paths, missing filenames, ambiguous sources, and inline attachments without
cidfail fast. Successful sends and dry-runs returnattachmentCountand safeattachmentDiagnostics: filename, MIME type, size, source, disposition, and cid. Diagnostics omit bytes, raw MIME, and local file paths.For large files, upload with
imap_upload_filefirst and pass its returned localpath; for inline images, setcontentDisposition: "inline"and a matchingcid.After sending, a copy is saved to the account's Sent folder (unless
saveToSentis disabled on the account). The folder is resolved via the account'ssentFolderoverride → the server's\SentSPECIAL-USE flag → a list of known localized names ("Sent", "Gesendet", "Éléments envoyés", …). The response reports the outcome:savedToSent(boolean),sentFolder(the folder used), and — when the save fails —sentSaveErrorexplaining why, instead of failing silently. The same applies toimap_reply_to_emailandimap_forward_email.When the account has
defaultBccconfigured, those address(es) are always BCC'd on send, reply, forward, and draft (merged with any per-callbcc; duplicates removed case-insensitively). The Bcc header is kept in the MIME stored for drafts and Sent-folder copies so mail clients show it. -
imap_save_draft: Save an email as a draft (no send). Takes the same fields as
imap_send_email, plusinReplyTo,references, and an optionalfolderoverride for the Drafts folder. -
imap_reply_to_email: Reply to an existing email
-
imap_forward_email: Forward an existing email
Folder Operations
-
imap_list_folders: List all folders
Each folder includes its
attributes(raw IMAP LIST flags) and, when the server advertises it,specialUse— the RFC 6154 role (\Sent,\Drafts,\Trash,\Junk,\Archive) that identifies a folder independent of its localized display name (e.g. "Gesendet" carriesspecialUse: "\Sent"). -
imap_folder_status: Get folder information
-
imap_create_folder: Create a new IMAP folder/mailbox. Most servers also create any missing parent folders. Returns success even if the folder already exists.
-
imap_get_unread_count: Count unread emails
Security
- Credentials are encrypted using AES-256-CBC encryption
- Encryption keys are stored separately in
~/.imap-mcp/.key - Account configurations are stored in
~/.imap-mcp/accounts.json - The store directory,
.key, andaccounts.jsonare written owner-only (0700/0600) so other local users cannot read the key or the credentials - The web setup wizard's HTTP API never returns stored passwords to the browser
- Downloaded attachments are confined to the downloads directory; sender-supplied filenames cannot write outside it
- Never commit or share your encryption key or account configurations
Development
Running in Development Mode
Building
Project Structure
Example Usage in Claude
-
Add an account: "Add my Gmail account with username [email protected]"
-
Check new emails: "Show me the latest 5 emails from my Gmail account"
-
Search emails: "Search for emails from [email protected] in the last week"
-
Send an email: "Send an email to [email protected] with subject 'Project Update'"
-
Reply to emails: "Reply to the latest email from my boss"
-
Forward emails: "Forward the email with subject 'Meeting Notes' to [email protected]"
-
Move an email: "Move the invoice email from INBOX to my Taxes folder"
-
Manage folders: "List all folders in my email account and show unread counts"
Troubleshooting
Connection Issues
- Ensure your IMAP server settings are correct
- Check if your email provider requires app-specific passwords
- Verify that IMAP is enabled in your email account settings
- For sending emails, ensure your account has SMTP access enabled
Recipients arriving as ["[email protected]","[email protected]"]
to, cc, bcc, references and uid accept either a single value or an
array. In JSON Schema that is an anyOf, and some MCP clients drop the anyOf
before showing the schema to the model — the field then looks untyped or
string-typed, and the client serializes the model's array into a string. The
server used to pass that string straight to nodemailer, which folded the
literal [ and ] into the first and last address, so every recipient was
rejected by the receiving mail server (issue #127).
The server now detects a stringified array and restores it, both when
validating tool input and again before composing the message, and logs a
warning to stderr naming the field. Nothing needs to change on your side. If
you want to bypass the client behavior entirely, pass recipients as one
comma-separated string: "Alice <[email protected]>, Bob <[email protected]>".
Search returns nothing although the folder has mail (Strato)
Since mid-2026 Strato's IMAP server (imap.strato.com) answers every SEARCH
command with an empty result, while FETCH still works (issue #138). The server
detects this: when a SEARCH comes back empty for a folder that is not empty and
SEARCH ALL is empty as well, it fetches the envelopes and applies the
criteria itself. imap_search_emails, imap_find_thread_messages, the unread counts and the
spam analysis keep working; imap_get_latest_emails never needed SEARCH.
Limits of the fallback:
- It is slower — every envelope of the folder is downloaded per search.
- A
bodysearch downloads and parses each remaining candidate, so it is refused above 2000 candidates; narrow it withsince/from/subject. - Deleting tools (
imap_bulk_delete_by_search,imap_delete_spam,imap_delete_by_domain) do not use it and return an error instead. Find the messages withimap_search_emailsand delete their UIDs withimap_bulk_delete.
SMTP Configuration
The server automatically configures SMTP settings based on your IMAP provider. If you need custom SMTP settings, you can specify them when adding an account:
Common IMAP Settings
-
Gmail:
- Host: imap.gmail.com
- Port: 993
- Requires app-specific password
-
Outlook/Hotmail:
- Host: outlook.office365.com
- Port: 993
-
Yahoo:
- Host: imap.mail.yahoo.com
- Port: 993
- Requires app-specific password
License
MIT
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
来源:README.md,提交 bd47426
工具
0版本历史
4- v2.2.0最新Oct 9, 2026
- v2.1.1Oct 9, 2026
- v2.1.0Sep 26, 2026
- v2.0.0Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分