Skip to main content
Glama

send-email

Send emails via the Email MCP server by specifying recipients, subject, and content. Supports plain text and HTML formats with JWT authentication for secure communication.

Instructions

发送邮件

Input Schema

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

Implementation Reference

  • The main handler function returned by createSendEmailTool, which validates config, sends email via Gmail API or SMTP (with attachments support), and returns success/error MCP content.
    export function createSendEmailTool() { return async (args: SendEmailArgs) => { 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 schema used for validating input arguments to the send_email tool.
    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(), });
  • src/index.ts:84-124 (registration)
    Registration of the 'send_email' tool in the MCP tools list, defining name, description, and JSON schema.
    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"], }, },
  • Main MCP server handler that dispatches to the send_email tool implementation.
    case "send_email": { const args = SendEmailSchema.parse(request.params.arguments); const sendEmailTool = createSendEmailTool(); return await sendEmailTool(args); }
  • TypeScript interface defining the shape of SendEmailArgs used in the handler.
    interface SendEmailArgs { to: string; // 收件人 subject: string; // 邮件主题 body: string; // 邮件内容 from?: string; // 发件人(可选) html?: boolean; // 是否为HTML格式 attachments?: Array<{ filename: string; // 附件文件名 path?: string; // 文件路径 content?: string; // 文件内容 }>; }

Other Tools

Related 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