简单电子邮件服务
一个简单的Express.js服务,作为您MCP服务器的电子邮件工具。此服务允许您发送带有自定义主题和正文内容的电子邮件,并自动以“Shreyas”署名。
特点/特性
- 通过SMTP发送电子邮件
- 来自“Shreyas”的自动签名
- 支持HTML和纯文本电子邮件
- 输入验证
- 健康检查端点
- 已启用CORS以支持跨域请求
- 通过过滤器(发件人、主题、自由文本、日期范围)读取Gmail中的电子邮件
- 创建包含Google Meet链接的Google日历事件
设置
1. 安装依赖项
npm install2. 配置环境变量
复制示例环境文件并配置您的SMTP设置:
cp env.example .env编辑 .env 附上您的SMTP配置文件:
# SMTP Configuration
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your-email@gmail.com
SMTP_PASS=your-app-password
# Server Configuration
PORT=3000
# Google OAuth2 for Gmail & Calendar
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/oauth2/callback
GOOGLE_REFRESH_TOKEN=your-refresh-token3. Gmail/日历设置
- 在您的Google Cloud项目中启用API:Gmail API和Google Calendar API
- 创建一个OAuth 2.0客户端并配置授权重定向URI
- 使用下面的OAuth流程来生成一个刷新令牌
OAuth 流程(用于生成刷新令牌)
- 启动服务器,然后打开:
- GET http://localhost:3000/oauth2/init?scope=both (默认包含Gmail + 日历)
- 访问该网址,同意使用该账户
- 您将被重定向到
GOOGLE_REDIRECT_URI和;与?code=... - 呼叫
GET http://localhost:3000/oauth2/callback?code=... - 复制
refresh_token进入.envasGOOGLE_REFRESH_TOKEN,重启
4. 启动服务
npm run dev # development
npm start # productionAPI 端点
健康检查
GET /health发送电子邮件
POST /send-email阅读电子邮件(Gmail)
POST /read-email安排Google Meet会议(使用日历)
POST /schedule-meet在主日历上创建一个包含Meet链接的日历事件。
请求体:
{
"title": "Design sync",
"description": "Review MCP server changes",
"start": "2025-10-21T10:00:00Z",
"end": "2025-10-21T10:30:00Z",
"timeZone": "UTC",
"attendees": ["alice@example.com", "bob@example.com"],
"sendUpdates": "all",
"reminders": { "useDefault": true }
}回复(示例):
{
"success": true,
"id": "eventId",
"htmlLink": "https://www.google.com/calendar/event?eid=...",
"status": "confirmed",
"meetLink": "https://meet.google.com/abc-defg-hij",
"start": { "dateTime": "2025-10-21T10:00:00Z", "timeZone": "UTC" },
"end": { "dateTime": "2025-10-21T10:30:00Z", "timeZone": "UTC" },
"attendees": [ { "email": "alice@example.com" }, { "email": "bob@example.com" } ]
}列出日历事件
POST /list-events查看日历事件,包括参与者、时间及详细信息。
请求体(过滤器):
{
"timeMin": "2025-10-20T00:00:00Z",
"timeMax": "2025-10-27T23:59:59Z",
"maxResults": 10,
"q": "meeting",
"calendarId": "primary"
}回复(示例):
{
"success": true,
"total": 2,
"timeZone": "America/New_York",
"events": [
{
"id": "eventId1",
"summary": "Design sync",
"description": "Review MCP server changes",
"start": { "dateTime": "2025-10-21T10:00:00Z", "timeZone": "UTC" },
"end": { "dateTime": "2025-10-21T10:30:00Z", "timeZone": "UTC" },
"location": "",
"attendees": [
{ "email": "alice@example.com", "displayName": "Alice", "responseStatus": "accepted" },
{ "email": "bob@example.com", "displayName": "Bob", "responseStatus": "needsAction" }
],
"organizer": { "email": "you@example.com", "displayName": "You" },
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=...",
"meetLink": "https://meet.google.com/abc-defg-hij",
"created": "2025-10-20T15:30:00.000Z",
"updated": "2025-10-20T15:30:00.000Z"
}
]
}注释:
- 需要日历范围权限
https://www.googleapis.com/auth/calendar.events(默认包含在/oauth2/init?scope=both)。 - 会议链接已通过(以下方式)提供
conferenceData.createRequest。 timeMin/timeMax用于按时间范围过滤事件的ISO日期字符串。q自由文本搜索查询。maxResults上限为250。
安全与故障排除
- 保持
.env脱离版本控制 - 如果你收到403 accessNotConfigured错误,请在Google Cloud控制台中启用该API
- 确保OAuth客户端和已启用的API属于同一个项目
