Skip to main content
Glama
wyccywwyc

Email Sender MCP Server

by wyccywwyc

📧 邮件发送 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,默认为 False

  • use_ssl (bool, 可选): 是否使用SSL,默认为 False

  • attachments (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: 项目配置文件

⚠️ 注意事项

  1. 密码安全: 不要在代码中硬编码密码,使用环境变量或配置文件

  2. 授权码: 大多数邮箱服务商需要使用授权码而不是登录密码

  3. 端口选择:

    • 端口 25: 通常不需要加密(可能被某些网络阻止)

    • 端口 587: 使用 STARTTLS(推荐)

    • 端口 465: 使用 SSL/TLS

  4. 附件路径: 附件文件路径必须是绝对路径或相对于工作目录的路径

🐛 故障排除

认证失败

  • 检查邮箱和密码/授权码是否正确

  • 确认是否使用了授权码而不是登录密码

  • 检查 SMTP 服务是否已开启

连接失败

  • 检查 SMTP 服务器地址和端口是否正确

  • 确认网络连接正常

  • 检查防火墙设置

发送失败

  • 检查收件人邮箱地址格式是否正确

  • 确认附件文件路径存在且可读

  • 查看错误信息中的详细提示

📄 许可证

MIT License

-
security - not tested
F
license - not found
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/wyccywwyc/emailMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server