Email MCP Server logo

Email MCP Server

Community
guangxiangdebizi

通用多邮箱 MCP 服务:原生 Streamable HTTP,固定 5 个工具,支持 IMAP/SMTP、Gmail API、多账号切换及 Env/Header 配置。

Publisherguangxiangdebizi
Repositoryemail-mcp
LanguageTypeScript
Forks
2
Stars
14
Available tools
0
Transport typestreamable-http
Categories
LicenseISC
Links
  • Connect tools to AI workflows

    Email MCP Server exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    14 stars and 2 forks from the linked repository.

Email MCP Server

一个基于 MCP Streamable HTTP 的通用邮箱服务。固定提供 5 个工具,支持通过标准 IMAP/SMTP 使用 QQ、163、126、Gmail、Outlook、Yahoo、iCloud、企业邮箱和自建邮箱, 同时保留 Gmail API 模式。

解决的问题

Issue #1 的根因是旧版本只有 send_email 使用 SMTP;读取、搜索、删除和回复全部写死为 Gmail API,因此 163 等邮箱只能发信。当前实现改为:

  • send_email、reply_email:标准 SMTP(或 Gmail API)。
  • read_emails、search_emails、delete_email:标准 IMAP(或 Gmail API)。
  • 工具总数仍为 5,名称保持不变。
  • 每个工具都有可选 account 参数,可在命名账号之间逐次调用切换。
  • 每个 HTTP 请求也可使用 X-Email-* Header 切换或覆盖连接配置,无需重启服务。

安装与启动

要求 Node.js 18 或更高版本。

从 npm 全局安装:

bash
npm install -g @xingyuchen/email-mcp
email-mcp-server

从源码运行:

bash
npm install
cp .env.example .env
npm run build
npm start

默认仅监听本机回环地址:

text
http://localhost:3200/mcp

健康检查:

bash
curl http://localhost:3200/health

这是原生 Streamable HTTP MCP,不再需要 SuperGateway,也不是旧的 /sse 协议。

原生 HTTPS(跨机器部署必须启用)

配置服务器证书和私钥后,服务会直接启动为 HTTPS。TLS 会加密完整 HTTP 请求,包括 Authorization、所有 X-Email-* 请求头以及 JSON-RPC 正文,服务端解密后仍按原有方式 解析和使用这些字段:

env
MCP_HOST=0.0.0.0
MCP_PORT=3200
MCP_TLS_KEY_PATH=/etc/email-mcp/tls/server.key
MCP_TLS_CERT_PATH=/etc/email-mcp/tls/server.crt
MCP_TLS_MIN_VERSION=TLSv1.2

客户端连接:

text
https://mail-mcp.example.com:3200/mcp

证书必须由客户端信任,并且证书域名必须与 URL 主机名匹配。只配置证书或只配置私钥会 拒绝启动。非回环地址上的明文 HTTP 也会默认拒绝启动。

MCP_API_KEY 默认不启用。部署者需要额外的客户端鉴权时,可显式设置至少 32 字节的 MCP_API_KEY;设置后客户端再通过 Bearer 或 X-MCP-API-Key 发送它。

也可以由 Nginx、Caddy 或负载均衡器终止 HTTPS,此时保持 MCP_HOST=127.0.0.1,只允许 代理通过本机回环访问后端。只有代理可信且会覆盖 X-Forwarded-Proto 时才设置 MCP_TRUST_PROXY=true。如果要求 TLS 一直终止到 Node.js 进程,请使用上述原生 HTTPS。

单邮箱配置

163 邮箱

先在 163 邮箱设置中启用 SMTP/IMAP,并使用客户端授权码而不是登录密码:

env
EMAIL_PROVIDER=imap-smtp
SMTP_HOST=smtp.163.com
SMTP_PORT=465
SMTP_SECURE=true
SMTP_USER=your-email@163.com
SMTP_PASS=your-authorization-code
IMAP_HOST=imap.163.com
IMAP_PORT=993
IMAP_SECURE=true
IMAP_USER=your-email@163.com
IMAP_PASS=your-authorization-code
DEFAULT_FROM_EMAIL=your-email@163.com

对于常见邮箱,可只配置账号和授权码,服务器会根据邮箱域名补全主机、端口和 TLS:

env
EMAIL_PROVIDER=imap-smtp
SMTP_USER=your-email@qq.com
SMTP_PASS=your-authorization-code
DEFAULT_FROM_EMAIL=your-email@qq.com

当 IMAP_USER/IMAP_PASS 未设置时,会复用 SMTP 凭据;反向亦然。企业邮箱或自建邮箱 只需显式填写对应的 SMTP_* 和 IMAP_* 地址即可。

Gmail API 兼容模式

env
EMAIL_PROVIDER=gmail-api
GMAIL_CLIENT_ID=...
GMAIL_CLIENT_SECRET=...
GMAIL_REFRESH_TOKEN=...
DEFAULT_FROM_EMAIL=your-email@gmail.com

也可只传有效的 GMAIL_ACCESS_TOKEN。如果使用 Gmail 的标准 IMAP/SMTP,则将 EMAIL_PROVIDER 设为 imap-smtp 并使用应用专用密码。

多邮箱切换(不增加工具)

使用 EMAIL_ACCOUNTS_JSON 定义命名账号:

env
EMAIL_DEFAULT_ACCOUNT=personal
EMAIL_ACCOUNTS_JSON={"personal":{"provider":"imap-smtp","from":"me@qq.com","smtp":{"user":"me@qq.com","pass":"qq-code"},"imap":{"user":"me@qq.com","pass":"qq-code"}},"work":{"provider":"imap-smtp","from":"me@outlook.com","smtp":{"user":"me@outlook.com","pass":"work-code"},"imap":{"user":"me@outlook.com","pass":"work-code"}}}

随后直接在原有工具中选择账号:

json
{
  "account": "work",
  "limit": 10,
  "folder": "INBOX"
}

read_emails 和 search_emails 返回的 messageId 是不包含密码的定位符,其中保留了 命名账号和 IMAP 文件夹信息。把它直接传给 reply_email 或 delete_email 时,通常无需 再次填写 account。

通过请求头配置或切换邮箱

MCP 客户端可以为 Streamable HTTP 连接设置静态 Header:

json
{
  "mcpServers": {
    "email": {
      "type": "streamable-http",
      "url": "https://mail-mcp.example.com:3200/mcp",
      "headers": {
        "X-Email-Account": "work"
      }
    }
  }
}

也可以完全通过 Header 提供连接信息:

json
{
  "X-Email-Provider": "imap-smtp",
  "X-Email-From": "me@example.com",
  "X-Email-SMTP-Host": "smtp.example.com",
  "X-Email-SMTP-Port": "465",
  "X-Email-SMTP-Secure": "true",
  "X-Email-SMTP-User": "me@example.com",
  "X-Email-SMTP-Pass": "app-password",
  "X-Email-IMAP-Host": "imap.example.com",
  "X-Email-IMAP-Port": "993",
  "X-Email-IMAP-Secure": "true",
  "X-Email-IMAP-User": "me@example.com",
  "X-Email-IMAP-Pass": "app-password"
}

还支持 X-Email-Config,值为完整 JSON,或 base64:<base64url-json>。可用字段与 EMAIL_ACCOUNTS_JSON 内单个账号相同。Base64url 只是编码,不是加密;机密性由 HTTPS 提供。

配置优先级从高到低:

  1. 单独的 X-Email-* 连接 Header。
  2. X-Email-Config。
  3. account 参数或 X-Email-Account 选中的命名账号。
  4. 普通环境变量。

账号选择优先级为:工具 account > X-Email-Account > X-Email-Config.account > EMAIL_DEFAULT_ACCOUNT。

Header 中可能包含邮箱授权码。跨机器部署时必须使用 HTTPS;需要客户端鉴权时再设置 MCP_API_KEY。不要在日志中打印请求头。

固定的 5 个工具

工具用途主要协议
send_email发送纯文本/HTML 邮件及附件SMTP / Gmail API
read_emails读取文件夹,可只读未读邮件IMAP / Gmail API
search_emails搜索指定文件夹IMAP / Gmail API
delete_email删除指定邮件IMAP / Gmail API
reply_email回复或回复全部IMAP + SMTP / Gmail API

五个工具均支持可选 account 参数。

通用 IMAP 搜索支持普通文本,以及:

text
from:alice@example.com subject:"quarterly report" since:2026-01-01 before:2026-08-01 is:unread

服务配置

环境变量默认值说明
MCP_HOST127.0.0.1HTTP/HTTPS 监听地址
MCP_PORT3200HTTP/HTTPS 端口
MCP_PATH/mcpStreamable HTTP 路径
MCP_API_KEY空可选;设置后启用 Bearer / X-MCP-API-Key 鉴权,网络部署至少 32 字节
MCP_CORS_ORIGIN空可选 CORS 来源,多个值用逗号分隔
MCP_TLS_KEY_PATH空原生 HTTPS 私钥文件;必须与证书同时配置
MCP_TLS_CERT_PATH空原生 HTTPS 证书链文件
MCP_TLS_KEY_PASSPHRASE空可选私钥口令
MCP_TLS_MIN_VERSIONTLSv1.2允许 TLSv1.2 或 TLSv1.3
MCP_TLS_CA_PATH空可选 mTLS 客户端 CA
MCP_TLS_REQUIRE_CLIENT_CERTfalse是否强制验证客户端证书
MCP_TRUST_PROXYfalse是否信任代理提供的 X-Forwarded-Proto
EMAIL_ALLOW_INSECURE_TRANSPORTfalse仅测试用;允许不使用 TLS 的 SMTP/IMAP
EMAIL_ALLOW_INVALID_TLS_CERTIFICATESfalse仅测试用;允许关闭邮箱服务器证书校验

验证

bash
npm test

共 15 项自动化测试,覆盖配置优先级、163 IMAP 泛化、命名账号切换、请求头覆盖、消息 定位符、搜索语法、标准 IMAP 读/搜/删、SMTP 发/回、HTTP/HTTPS Streamable HTTP、网络部署 安全策略、证书校验保护、强制 STARTTLS 和工具数量不变约束。

Use Email MCP Server MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once Email MCP Server is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP connects through a hosted MCP server URL in TypingMind.

Add an MCP server URL

Use this when Email MCP Server is already hosted remotely or your team wants one shared connector that multiple users can access.

1

Open MCP connectors

In TypingMind, go to Plugins, open MCP connectors, then choose Add URL.

  1. Open TypingMind in your browser.
  2. Go to Plugins.
  3. Open MCP connectors.
  4. Click Add URL.
TypingMind Add Custom MCP Server URL form
2

Paste the server URL

Enter the MCP server URL from the provider in the Server URL field. Add a connection name, description, icon, custom HTTP headers, or OAuth client settings if the server requires them.

  1. Paste the MCP server URL from the provider into the Server URL field.
  2. Enter a connection name for Email MCP Server.
  3. Add a description and icon if you want it to be easier to identify.
  4. Add custom HTTP headers or OAuth client details if the server requires authentication.
3

Create the connection

Click Create connection, then return to the Plugins list and confirm the new MCP connection is active.

  1. Click Create connection.
  2. Return to the MCP connectors list.
  3. Confirm the Email MCP Server connection appears as active.
  4. Refresh the plugin list if the connection does not appear immediately.
4

Switch models without reconnecting

Start a chat with your preferred model, enable the Email MCP Server tools from Plugins, and switch to another model whenever needed. The MCP connection stays available to the TypingMind workspace.

  1. Start a new chat in TypingMind.
  2. Select the AI model you want to use.
  3. Enable the Email MCP Server tools from Plugins.
  4. Ask the model to use the tool when needed.
  5. Switch to another AI model and reuse the same MCP connection.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use Email MCP Server to help me with this task?
Email MCP Server
Sure. I read it.
Here is what I found using Email MCP Server.

Frequently asked questions

What is the Email MCP Server MCP server used for?

Email MCP Server is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use Email MCP Server MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use Email MCP Server with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use Email MCP Server MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With Email MCP Server connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect Email MCP Server MCP to TypingMind?

Email MCP Server can be connected in TypingMind by adding its hosted MCP server URL. This is useful when you want a remote MCP connection that is available from your TypingMind workspace.

What tools does Email MCP Server MCP provide in TypingMind?

Email MCP Server exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use Email MCP Server MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If Email MCP Server requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇