Skip to main content
Glama

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_emailreply_email:标准 SMTP(或 Gmail API)。

  • read_emailssearch_emailsdelete_email:标准 IMAP(或 Gmail API)。

  • 工具总数仍为 5,名称保持不变。

  • 每个工具都有可选 account 参数,可在命名账号之间逐次调用切换。

  • 每个 HTTP 请求也可使用 X-Email-* Header 切换或覆盖连接配置,无需重启服务。

Related MCP server: MCP Email Server

安装与启动

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

从 npm 全局安装:

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

从源码运行:

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

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

http://localhost:3200/mcp

健康检查:

curl http://localhost:3200/health

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

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

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

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

客户端连接:

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,并使用客户端授权码而不是登录密码:

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:

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 兼容模式

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 定义命名账号:

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

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

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

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

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

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

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

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

{
  "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 搜索支持普通文本,以及:

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

服务配置

环境变量

默认值

说明

MCP_HOST

127.0.0.1

HTTP/HTTPS 监听地址

MCP_PORT

3200

HTTP/HTTPS 端口

MCP_PATH

/mcp

Streamable 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_VERSION

TLSv1.2

允许 TLSv1.2TLSv1.3

MCP_TLS_CA_PATH

可选 mTLS 客户端 CA

MCP_TLS_REQUIRE_CLIENT_CERT

false

是否强制验证客户端证书

MCP_TRUST_PROXY

false

是否信任代理提供的 X-Forwarded-Proto

EMAIL_ALLOW_INSECURE_TRANSPORT

false

仅测试用;允许不使用 TLS 的 SMTP/IMAP

EMAIL_ALLOW_INVALID_TLS_CERTIFICATES

false

仅测试用;允许关闭邮箱服务器证书校验

验证

npm test

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

Available Tools

1 tool
send-emailC

发送邮件

ParametersJSON Schema
NameRequiredDescriptionDefault
toYes邮件收件人
textYes邮件内容
subjectYes邮件主题

TDQS

C2.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations and no description of behavioral aspects like side effects, authorization, or error states.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single phrase is concise but lacks substance; not every word earns its place as it merely restates the name.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema or annotations, the description provides insufficient context for correct tool invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema descriptions cover all parameters (100%), so baseline 3 applies; description adds no extra meaning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description '发送邮件' is a tautology, restating the tool name 'send-email' with no added specificity or differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No usage guidance provided; no mention of when to use this tool versus alternatives (none exist) or caveats.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 1 tool update
    • First observedsend-email

TDQS

C2.7/5.0

Scored across 1 tool

Disambiguation5/5

Only one tool exists, so there is no risk of confusion between tools.

Naming Consistency5/5

With a single tool, naming consistency is trivially maintained.

Tool Count2/5

A single send-email tool is too few for an email MCP server, which typically requires additional capabilities like reading, listing, or managing emails.

Completeness2/5

The tool surface is severely incomplete, covering only sending emails with no support for receiving, listing, or other common email operations.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    A Model Context Protocol server that provides a seamless email management interface through Claude, allowing users to search, read, and send emails directly through natural language conversations.
    4
    114
    MIT
  • A
    license
    Not graded
    quality
    F
    maintenance
    A Model Context Protocol server that enables LLMs to compose and send emails with attachments, as well as search for files in specified directories that match given patterns.
    80
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that exposes multiple AI tools over SSE transport with JWT-based secure authentication, allowing for dynamic tool registration and session management.
    3,970
    4
    MIT
  • A
    license
    Not graded
    quality
    Not graded
    maintenance
    A Model Context Protocol server that provides email access via IMAP and SMTP, enabling AI agents to read, search, send, and manage emails. It features specialized tools for folder management, message retrieval, and replying to threads through a standardized HTTP/SSE interface.
    -