Skip to main content
Glama

send-email

Send emails directly from AI models using the Email MCP server. Specify recipient, subject, and content to dispatch messages with JWT authentication.

Instructions

发送邮件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYes邮件收件人
subjectYes邮件主题
textYes邮件内容

Implementation Reference

  • Core handler function for sending emails. Supports Gmail OAuth2 API and generic SMTP. Handles attachments, HTML, configuration from env vars, and returns formatted MCP content response.
    export function createSendEmailTool() { return async (args) => { try { const config = getEmailConfig(); // 验证必需的环境变量 if (config.provider === "gmail") { if (!config.gmail?.clientId || !config.gmail?.clientSecret || !config.gmail?.refreshToken) { throw new Error("Gmail配置缺失。请设置 GMAIL_CLIENT_ID, GMAIL_CLIENT_SECRET, 和 GMAIL_REFRESH_TOKEN"); } } else { if (!config.smtp?.auth.user || !config.smtp?.auth.pass) { throw new Error("SMTP配置缺失。请设置 SMTP_USER 和 SMTP_PASS"); } } if (!config.defaultFrom) { throw new Error("DEFAULT_FROM_EMAIL 环境变量是必需的"); } let result; if (config.provider === "gmail") { result = await sendViaGmail(args, config); } else { result = await sendViaSMTP(args, config); } return { content: [ { type: "text", text: `✅ 邮件发送成功!\n\n详情:\n- 收件人: ${args.to}\n- 主题: ${args.subject}\n- 提供商: ${result.provider}\n- 消息ID: ${result.messageId}\n- 格式: ${args.html ? "HTML" : "纯文本"}${args.attachments ? `\n- 附件数量: ${args.attachments.length}` : ""}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "发生未知错误"; return { content: [ { type: "text", text: `❌ 邮件发送失败: ${errorMessage}`, }, ], }; } }; }
  • Zod validation schema for send_email tool input arguments.
    const SendEmailSchema = z.object({ to: z.string().email(), subject: z.string(), body: z.string(), from: z.string().email().optional(), html: z.boolean().optional(), attachments: z.array(z.object({ filename: z.string(), path: z.string().optional(), content: z.string().optional(), })).optional(), });
  • dist/index.js:65-105 (registration)
    MCP tool registration for 'send_email', including metadata and input schema for tool discovery via ListTools.
    name: "send_email", description: "Send an email to specified recipients", inputSchema: { type: "object", properties: { to: { type: "string", description: "Recipient email address", }, subject: { type: "string", description: "Email subject", }, body: { type: "string", description: "Email body content", }, from: { type: "string", description: "Sender email address (optional)", }, html: { type: "boolean", description: "Whether the body is HTML format", }, attachments: { type: "array", description: "Email attachments", items: { type: "object", properties: { filename: { type: "string" }, path: { type: "string" }, content: { type: "string" }, }, }, }, }, required: ["to", "subject", "body"], }, },
  • Server-side dispatch handler that routes 'send_email' calls, validates args, instantiates tool, and executes.
    case "send_email": { const args = SendEmailSchema.parse(request.params.arguments); const sendEmailTool = createSendEmailTool(); return await sendEmailTool(args);

Other Tools

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/guangxiangdebizi/email-mcp'

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