GmailSend MCP
用于通过Gmail SMTP发送电子邮件的最小MCP(模型上下文协议)服务器。暴露单个 send_email 工具通过stdio传输到Claude。
先决条件
1.净10 SDK
从以下位置安装 dot.net.
2.Gmail应用程序密码
需要启用两步验证的Google帐户。
- 首选 myaccount.google.com/apppasswords
- 创建一个新的应用程序密码——将其标记为
claude-mcp - 复制16个字符的密码(格式:
xxxx xxxx xxxx xxxx)
设置
环境变量
服务器在启动时从环境变量中读取凭据,如果缺少凭据,将拒绝启动。
| 变量 | 示例值 |
|---|---|
GMAIL_ADDRESS | you@gmail.com |
GMAIL_APP_PASSWORD | abcd efgh ijkl mnop |
项目MCP配置(克劳德代码)
A. .mcp.json 从该项目目录运行Claude Code时使用该文件。它被git忽略,因为它包含凭据。
复制模板并填写您的凭据:
cp .mcp.json.example .mcp.json # if you create one, or edit .mcp.json directly编辑 .mcp.json:
{
"mcpServers": {
"gmail": {
"command": "dotnet",
"args": ["run", "--project", "gmail-mcp"],
"env": {
"GMAIL_ADDRESS": "you@gmail.com",
"GMAIL_APP_PASSWORD": "abcd efgh ijkl mnop"
}
}
}
}Claude桌面配置
添加 %APPDATA%\Claude\claude_desktop_config.json (Windows)或 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"gmail": {
"command": "dotnet",
"args": ["run", "--project", "C:/path/to/GmailSend-mcp/gmail-mcp"],
"env": {
"GMAIL_ADDRESS": "you@gmail.com",
"GMAIL_APP_PASSWORD": "abcd efgh ijkl mnop"
}
}
}
}为了更快地启动,请更换dotnet run --project gmail-mcp运行后编译的二进制文件的路径dotnet publish.
用法
一旦注册,克劳德将有权访问 send_email 工具。
工具: send_email
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
to | string | yes | 收件人地址,逗号分隔 |
subject | string | yes | 电子邮件主题行 |
body | string | yes | 电子邮件正文内容 |
cc | string | no | 抄送收件人,逗号分隔 |
bcc | string | no | 密件抄送收件人,逗号分隔 |
is_html | bool | no | 以HTML格式发送正文(默认值:false) |
示例提示
Send an email to alice@example.com with subject "Meeting notes" and a summary of our conversation.Draft and send a HTML-formatted status update to the team at team@example.com.Email bob@example.com and cc carol@example.com to let them know the deploy succeeded.能力
- 通过Gmail SMTP发送纯文本或HTML电子邮件
- 收件人、抄送和密件抄送上有多个收件人(逗号分隔)
- 仅来自环境变量的凭据——代码中没有存储任何凭据
局限性
- 仅限Gmail --硬编码为
smtp.gmail.com:587与STARTTLS - 需要应用程序密码 --不支持OAuth2
- 无附件
- 无已发送邮件跟踪 --该工具返回成功/失败字符串,但不验证交付
- Gmail发送限制 --Gmail强制普通账户每天发送500封电子邮件
dotnet run启动延迟 --每次Claude会话都会通过以下方式冷启动服务器dotnet run。使用已发布的二进制文件来减少此问题
发展
# Build
dotnet build
# Run tests
dotnet test
# Run a single test class
dotnet test --filter "FullyQualifiedName~EmailService"
# Run the server manually (requires env vars)
$env:GMAIL_ADDRESS="you@gmail.com"
$env:GMAIL_APP_PASSWORD="xxxx xxxx xxxx xxxx"
dotnet run --project gmail-mcp项目结构
gmail-mcp/
├── Program.cs — DI wiring, env var validation, MCP stdio server
├── EmailService.cs — IEmailService interface + MailKit SMTP implementation
└── SendEmailTool.cs — MCP tool definition ([McpServerTool] attribute)
gmail-mcp.Tests/
├── EmailServiceTests.cs — Unit tests for credential validation and message construction
└── SendEmailToolTests.cs — Unit tests for tool parameter validation and send behaviour