IMAP/SMTP Email MCP Server
Enables email management via IMAP/SMTP, supporting list emails, read emails, send emails, and save drafts.
README
IMAP/SMTP Email MCP Server
简介
这是一个标准的 Model Context Protocol (MCP) 服务器,用于连接用户的邮箱并进行邮件管理。支持所有标准的 IMAP/SMTP 协议。
提供了以下核心 MCP Tools 供 LLM 调用:
list_emails: 快速获取邮件列表元数据(发件人、标题、日期等),极大减少不必要的流量消耗。read_email: 根据邮件 ID 提取指定邮件的完整正文,内置 HTML 解析和标签剔除功能,有效避免 Token 超限。send_email: 通过 SMTP 发送简单纯文本邮件(自动适配 465/SSL 和 587/STARTTLS 端口)。save_draft: 通过 IMAP 保存邮件到草稿箱,内置常见中英文草稿箱文件夹的自动适配。
注:为了隐私与安全,账号配置信息通过 MCP 客户端的环境变量 (env) 注入,代码完全解耦且无状态,LLM 仅需调用极简的工具指令即可,无需接触密码。
项目结构
本仓库符合标准的 Python MCP 项目规范:
server.py:MCP 服务器的主入口逻辑。pyproject.toml/requirements.txt:项目依赖管理配置。
快速运行与使用
1. 安装依赖
pip install -r requirements.txt
# 或者
pip install .
2. 在支持 MCP 的客户端中配置(通过环境变量传入账号配置)
对于无状态的 MCP Server,使用 环境变量 (Environment Variables) 注入鉴权信息是最标准、最安全的做法。
选项 A:Claude Desktop 配置文件模板
请打开或创建配置文件(通常位于 ~/Library/Application Support/Claude/claude_desktop_config.json 或 %APPDATA%\Claude\claude_desktop_config.json),添加以下内容(注意其中的 env 字段):
{
"mcpServers": {
"email-server": {
"command": "python3",
"args": [
"/Users/你的用户名/Code/imap-smtp-mcp/server.py"
],
"env": {
"EMAIL_USERNAME": "your_email@qiye.163.com",
"EMAIL_PASSWORD": "your_client_auth_code",
"IMAP_SERVER": "imap.qiye.163.com",
"SMTP_SERVER": "smtp.qiye.163.com",
"IMAP_PORT": "993",
"SMTP_PORT": "465"
}
}
}
}
(注:Windows 用户请使用绝对路径,如 C:\\Code\\imap-smtp-mcp\\server.py。强烈建议在各大邮箱提供商中生成并使用第三方应用授权码代替主密码。)
选项 B:其他图形化客户端(如 Enchanté 等)
在添加 MCP Server 的配置界面中,除了填写路径,请务必找到 Environment Variables / Env 区域,并添加以下键值对:
EMAIL_USERNAME: your_email@qiye.163.com (你的网易企业邮箱账号)EMAIL_PASSWORD: your_client_auth_code (客户端授权密码)IMAP_SERVER: imap.qiye.163.comSMTP_SERVER: smtp.qiye.163.comIMAP_PORT: 993 (选填,网易企业邮箱默认的 SSL/TLS 端口即为 993)SMTP_PORT: 465 (选填,网易企业邮箱默认的 SSL/TLS 端口即为 465)
3. 运行与使用
配置完成并重启你的 MCP 客户端后,即可直接使用自然语言对 AI 助手下发指令,不需要告诉它任何密码或配置信息:
"帮我检查一下收件箱今天有没有重要的新邮件" "请帮我起草一封给 xxx@example.com 的会议纪要并保存到草稿箱"
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.