Email Sender MCP Server
Enables sending emails through SMTP with support for multiple recipients, attachments, CC/BCC, and both plain text and HTML formats. Includes preset configurations for common email providers like Gmail, QQ, Outlook, and 163.
README
📧 邮件发送 MCP 服务器
基于 email_sender.py 工具类构建的邮件发送 MCP 服务器,支持通过 Model Context Protocol 发送邮件。
✨ 功能特性
- ✅ 发送简单邮件(单个收件人)
- ✅ 发送完整邮件(支持多个收件人、附件、CC、BCC)
- ✅ 支持纯文本和 HTML 格式
- ✅ 支持自定义 SMTP 配置
- ✅ 支持常用邮箱预设配置(163、QQ、Gmail、Outlook等)
- ✅ 从环境变量读取配置
🚀 快速开始
1. 安装依赖
uv sync
2. 配置环境变量
创建 .env 文件或设置环境变量:
# SMTP 服务器配置
export SMTP_SERVER=smtp.qq.com
export SMTP_PORT=587
export SENDER_EMAIL=your-email@qq.com
export SENDER_PASSWORD=your-authorization-code
export USE_TLS=true
export USE_SSL=false
3. 在 Cursor 中配置 MCP 服务器
在 Cursor 的设置中添加 MCP 服务器配置:
{
"mcpServers": {
"email-sender": {
"command": "uv",
"args": [
"--directory",
"/Users/wangyichao/study/mcp/emailMCP",
"run",
"main.py"
],
"env": {
"SMTP_SERVER": "smtp.qq.com",
"SMTP_PORT": "587",
"SENDER_EMAIL": "your-email@qq.com",
"SENDER_PASSWORD": "your-authorization-code",
"USE_TLS": "true",
"USE_SSL": "false"
}
}
}
}
📋 可用工具
1. send_simple_email - 发送简单邮件
发送单个收件人的简单邮件。
参数:
receiver_email(str): 收件人邮箱地址subject(str): 邮件主题content(str): 邮件内容content_type(str, 可选): 内容类型,'plain' 或 'html',默认为 'plain'
示例:
send_simple_email(
receiver_email="recipient@example.com",
subject="测试邮件",
content="这是一封测试邮件",
content_type="plain"
)
2. send_email - 发送完整邮件
发送支持多个收件人、附件、CC、BCC 的完整邮件。
参数:
receiver_emails(List[str]): 收件人邮箱地址列表subject(str): 邮件主题content(str): 邮件内容content_type(str, 可选): 内容类型,'plain' 或 'html',默认为 'plain'attachments(List[str], 可选): 附件文件路径列表cc_emails(List[str], 可选): 抄送邮箱地址列表bcc_emails(List[str], 可选): 密送邮箱地址列表
示例:
send_email(
receiver_emails=["user1@example.com", "user2@example.com"],
subject="重要通知",
content="<h1>这是HTML邮件</h1><p>内容支持HTML格式</p>",
content_type="html",
cc_emails=["cc@example.com"],
attachments=["/path/to/file.pdf"]
)
3. send_email_with_custom_config - 使用自定义配置发送
使用自定义 SMTP 配置发送邮件,不依赖环境变量。
参数:
receiver_emails(List[str]): 收件人邮箱地址列表subject(str): 邮件主题content(str): 邮件内容smtp_server(str): SMTP服务器地址smtp_port(int): SMTP端口sender_email(str): 发件人邮箱sender_password(str): 发件人密码或授权码content_type(str, 可选): 内容类型,默认为 'plain'use_tls(bool, 可选): 是否使用TLS,默认为 Falseuse_ssl(bool, 可选): 是否使用SSL,默认为 Falseattachments(List[str], 可选): 附件文件路径列表cc_emails(List[str], 可选): 抄送邮箱地址列表bcc_emails(List[str], 可选): 密送邮箱地址列表
4. get_smtp_configs - 获取常用邮箱配置
获取常用邮箱的 SMTP 配置信息。
返回: JSON 格式的配置信息
5. get_current_config - 获取当前配置
获取当前使用的 SMTP 配置(从环境变量读取)。
返回: JSON 格式的配置信息(密码已隐藏)
📝 常用邮箱配置
QQ 邮箱
SMTP_SERVER=smtp.qq.com
SMTP_PORT=587
USE_TLS=true
USE_SSL=false
或使用 SSL:
SMTP_SERVER=smtp.qq.com
SMTP_PORT=465
USE_TLS=false
USE_SSL=true
注意: 需要使用授权码,不是登录密码。在 QQ 邮箱设置中开启 SMTP 服务并生成授权码。
163 邮箱
SMTP_SERVER=smtp.163.com
SMTP_PORT=25
USE_TLS=false
USE_SSL=false
或使用 SSL:
SMTP_SERVER=smtp.163.com
SMTP_PORT=465
USE_TLS=false
USE_SSL=true
Gmail
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
USE_TLS=true
USE_SSL=false
注意: Gmail 需要使用应用专用密码,不是普通密码。
Outlook
SMTP_SERVER=smtp-mail.outlook.com
SMTP_PORT=587
USE_TLS=true
USE_SSL=false
🔧 本地测试
直接运行服务器进行测试:
uv run main.py
📚 相关文件
email_sender.py: 邮件发送工具类main.py: MCP 服务器主文件pyproject.toml: 项目配置文件
⚠️ 注意事项
- 密码安全: 不要在代码中硬编码密码,使用环境变量或配置文件
- 授权码: 大多数邮箱服务商需要使用授权码而不是登录密码
- 端口选择:
- 端口 25: 通常不需要加密(可能被某些网络阻止)
- 端口 587: 使用 STARTTLS(推荐)
- 端口 465: 使用 SSL/TLS
- 附件路径: 附件文件路径必须是绝对路径或相对于工作目录的路径
🐛 故障排除
认证失败
- 检查邮箱和密码/授权码是否正确
- 确认是否使用了授权码而不是登录密码
- 检查 SMTP 服务是否已开启
连接失败
- 检查 SMTP 服务器地址和端口是否正确
- 确认网络连接正常
- 检查防火墙设置
发送失败
- 检查收件人邮箱地址格式是否正确
- 确认附件文件路径存在且可读
- 查看错误信息中的详细提示
📄 许可证
MIT License
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.
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.
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
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.
E2B
Using MCP to run code via e2b.