使用说明
电子邮件发件人MCP
英文|中文: README.md | README.zh-CN.md
一个MCP(模型上下文协议)服务器,它公开了一个 send_email SMTP工具
通知。这将启用“代理->SMTP服务器->个人电子邮件->电话”
通知”工作流。
目录
需求
- Node.js 18+
- 支持SMTP的电子邮件帐户(以及凭据或应用程序密码)
设置
- 安装依赖项:
npm install
- 配置SMTP凭据(建议通过
.env):
copy .env.example .env
编辑 .env 使用您的SMTP设置。
入门指南(推荐)
按照以下步骤完成推荐的MCP配置:
- 选择SMTP提供程序设置(主机/端口/安全/用户/密码)。
- 打开MCP客户端配置文件。
- 添加
email-sender下面的服务器条目。 - 将占位符SMTP值替换为您的真实凭据。
- 保存配置并重新启动MCP客户端。
- 打电话给
send_email该工具具有最小的有效载荷来验证。
环境变量
| 变量 | 必需 | 用途 | 示例/默认值 |
|---|---|---|---|
SMTP_URL |
否 | SMTP连接URL(简化配置) | smtps://user:pass@smtp.example.com:465 |
SMTP_HOST |
是* | SMTP服务器主机名 | smtp.gmail.com |
SMTP_PORT |
否 | SMTP服务器端口 | 465 或 587 |
SMTP_SECURE |
否 | 启用隐式TLS(465为真) | true / false |
SMTP_USER |
是* | SMTP用户名 | user@example.com |
SMTP_PASS |
是* | SMTP密码或应用程序密码 | app-password |
SMTP_FROM |
否 | 默认发件人地址 | 默认为 SMTP_USER |
SMTP_TLS_REJECT_UNAUTHORIZED |
否 | 允许自签名证书(不推荐) | false |
SMTP_CONN_TIMEOUT |
否 | 连接超时(ms) | 15000 |
SMTP_GREETING_TIMEOUT |
否 | 问候超时(ms) | 15000 |
SMTP_SOCKET_TIMEOUT |
否 | 套接字超时(ms) | 15000 |
SMTP_RETRY_ATTEMPTS |
否 | 重试尝试 | 默认值: 1 |
SMTP_RETRY_DELAY_MS |
否 | 初始重试延迟(ms) | 默认值: 500 |
SMTP_RETRY_BACKOFF |
否 | 重试回退倍数 | 默认值: 2 |
SMTP_RETRY_MAX_DELAY_MS |
否 | 最大重试延迟(ms) | 默认值: 5000 |
ATTACHMENT_ALLOWED_DIRS |
否 | 附件路径允许使用dirs | /path/to/uploads;/path/to/reports |
ATTACHMENT_MAX_BYTES |
否 | 最大附件大小(字节) | 默认值: 5242880 (5MB) |
RESPONSE_MAX_RECIPIENTS |
否 | 响应中返回的最大收件人数 | 默认值: 50 |
RESPONSE_MODE |
否 | 回复冗长(ok/minimal/summary) |
默认值: ok |
LOG_LEVEL |
否 | 记录冗长 | error / warn / info / debug |
*如果 SMTP_URL 提供, SMTP_HOST/SMTP_USER/SMTP_PASS 是可选的。在这种情况下,请确保 SMTP_FROM 已设置。
所需的最小配置为 SMTP_HOST, SMTP_USER,以及 SMTP_PASS (或 SMTP_URL + SMTP_FROM).
跑
npm start
这将通过stdio启动MCP服务器。不要在stdout所在的终端中运行它 其他输出需要。
通过npx运行
npx -y @agguy/email-sender-mcp@latest
MCP客户端配置
使用支持stdio的MCP客户端,并将其指向此服务器。
最小配置
{
"mcpServers": {
"email-sender": {
"command": "node",
"args": ["/absolute/path/to/email-sender-mcp/src/server.js"]
}
}
}
推荐配置
{
"mcpServers": {
"email-sender": {
"command": "npx",
"args": ["-y", "--quiet", "@agguy/email-sender-mcp@latest"],
"env": {
"SMTP_HOST": "smtp.example.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"SMTP_USER": "your-email@example.com",
"SMTP_PASS": "your-app-password",
"SMTP_FROM": "your-email@example.com"
}
}
}
}
最大配置(所有参数)
{
"mcpServers": {
"email-sender": {
"command": "node",
"args": ["/absolute/path/to/email-sender-mcp/src/server.js"],
"env": {
"SMTP_HOST": "smtp.example.com",
"SMTP_PORT": "465",
"SMTP_SECURE": "true",
"SMTP_USER": "your-email@example.com",
"SMTP_PASS": "your-app-password",
"SMTP_FROM": "your-email@example.com",
"SMTP_TLS_REJECT_UNAUTHORIZED": "true",
"SMTP_CONN_TIMEOUT": "15000",
"SMTP_GREETING_TIMEOUT": "15000",
"SMTP_SOCKET_TIMEOUT": "15000",
"SMTP_RETRY_ATTEMPTS": "3",
"SMTP_RETRY_DELAY_MS": "500",
"SMTP_RETRY_BACKOFF": "2",
"SMTP_RETRY_MAX_DELAY_MS": "5000",
"ATTACHMENT_ALLOWED_DIRS": "/path/to/uploads;/path/to/reports",
"ATTACHMENT_MAX_BYTES": "5242880",
"RESPONSE_MAX_RECIPIENTS": "50",
"LOG_LEVEL": "info"
}
}
}
}
确保环境变量可用于MCP过程。如果你的MCP
客户端支持传递env变量,在那里设置它们;否则,从以下位置运行客户端
带有a的项目目录 .env 文件。
工具:send_email
参数
| 字段 | 目的 |
|---|---|
to |
收件人(字符串、数组或 { name, address }) |
cc / bcc / replyTo |
可选收件人(格式与 to) |
from |
覆盖发件人地址 |
subject |
电子邮件主题 |
text |
纯文本正文 |
html |
HTML正文 |
template |
模板与 text/html 和 variables |
headers |
自定义标题 |
priority |
high / normal / low |
attachments |
附件(路径或内容) |
retry |
重试策略覆盖 |
smtp |
每次呼叫SMTP覆盖 |
requestId |
可选跟踪id |
responseMode |
响应模式: ok, minimal, summary |
最小示例
{
"to": "me@example.com",
"subject": "Hello",
"text": "Agent notification."
}
多个收件人(数组)
{
"to": ["me@example.com", "team@example.com"],
"subject": "Hello",
"text": "Agent notification."
}
地址对象(名称+地址)
{
"to": { "name": "Agguy", "address": "me@example.com" },
"subject": "Hello",
"text": "Agent notification."
}
模板示例
{
"to": "me@example.com",
"subject": "Hello",
"template": {
"text": "Hi {{name}}, build {{build}} completed.",
"variables": {
"name": "Agguy",
"build": "42"
}
}
}
附件、标题、优先级
{
"to": "me@example.com",
"subject": "Report",
"text": "See attachment.",
"priority": "high",
"headers": {
"X-Project": "email-sender-mcp"
},
"attachments": [
{
"filename": "report.txt",
"content": "Hello",
"encoding": "utf-8"
}
]
}
每次呼叫SMTP覆盖
{
"to": "me@example.com",
"subject": "Hello",
"text": "Agent notification.",
"smtp": {
"host": "smtp.example.com",
"port": 587,
"secure": false,
"user": "your-email@example.com",
"pass": "your-password"
}
}
重试覆盖+requestId
{
"requestId": "notify-42",
"to": "me@example.com",
"subject": "Hello",
"text": "Agent notification.",
"retry": {
"attempts": 3,
"delayMs": 500,
"backoffFactor": 2,
"maxDelayMs": 5000
}
}
最大示例(所有参数)
{
"requestId": "notify-42",
"to": [
{ "name": "Agguy", "address": "me@example.com" },
"team@example.com"
],
"cc": "cc@example.com",
"bcc": [{ "name": "Audit", "address": "audit@example.com" }],
"replyTo": { "name": "Support", "address": "support@example.com" },
"from": "sender@example.com",
"subject": "Build report",
"html": "<b>Build completed</b>",
"template": {
"text": "Hi {{name}}, build {{build}} completed.",
"variables": { "name": "Agguy", "build": "42" }
},
"headers": { "X-Project": "email-sender-mcp" },
"priority": "high",
"attachments": [
{ "filename": "note.txt", "content": "Hello", "encoding": "utf-8" },
{ "path": "/path/to/reports/report.pdf" }
],
"retry": {
"attempts": 3,
"delayMs": 500,
"backoffFactor": 2,
"maxDelayMs": 5000
},
"responseMode": "summary",
"smtp": {
"url": "smtps://user:pass@smtp.example.com:465",
"host": "smtp.example.com",
"port": 465,
"secure": true,
"user": "your-email@example.com",
"pass": "your-password",
"connectionTimeout": 15000,
"greetingTimeout": 15000,
"socketTimeout": 15000,
"tlsRejectUnauthorized": true
}
}
响应模式
ok:仅返回{"ok": true}取得圆满成功。如果任何接收者被拒绝, 返回错误有效载荷。minimal:返回计数和标识符(messageId、计数、尝试)。summary:返回计数加accepted/rejected列表(可能被截断)。
备注
text或html是必需的。您还可以使用template.text或template.html以生成内容。- 对于生产环境,更喜欢环境变量而不是在工具中传递凭据 电话。
- 地址字段接受逗号分隔的字符串或电子邮件地址数组。
- 响应是JSON字符串
messageId,accepted,以及rejected细节。 大型收件人列表可能会根据以下情况被截断RESPONSE_MAX_RECIPIENTS. - 当
RESPONSE_MODE=ok(或responseMode: "ok"),圆满成功只会回报{"ok": true}如果任何收件人被拒绝,则返回错误有效载荷。 - 连接路径受到以下限制
ATTACHMENT_ALLOWED_DIRS,并且大小有上限 通过ATTACHMENT_MAX_BYTES.