Skip to main content
Glama

mcp_email_send

Send emails through SMTP protocol by providing server credentials, recipient information, subject, and message content.

Instructions

发送邮件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesSMTP服务器主机名
portYesSMTP服务器端口号
subjectYes邮件主题
toYes收件人邮箱地址
bodyYes邮件正文
fromYes发件人邮箱地址
fromPasswordYes发件人邮箱密码

Implementation Reference

  • The MCP tool handler function for 'mcp_email_send'. It logs the input parameters, instantiates EmailService, calls sendEmail with the parameters, logs the result, and returns a formatted text content response.
    server.tool('mcp_email_send', "发送邮件", param, async (param) => { log(JSON.stringify(param)) // 调用EmailService发送邮件 const emailService = new EmailService(); const result = await emailService.sendEmail(param); log(JSON.stringify(result)) return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; })
  • Zod schema defining the input parameters for the mcp_email_send tool, including validation and descriptions.
    const param = { host: z.string().describe('SMTP服务器主机名'), port: z.number().int().positive().describe('SMTP服务器端口号'), subject: z.string().describe('邮件主题'), to: z.string().email("无效的邮箱地址").describe('收件人邮箱地址'), body: z.string().min(1, "邮件正文不能为空").describe('邮件正文'), from: z.string().email("无效的邮箱地址").describe('发件人邮箱地址'), fromPassword: z.string().min(1, "发件人邮箱密码不能为空").describe('发件人邮箱密码') }
  • src/server.ts:39-53 (registration)
    Registration of the 'mcp_email_send' tool with the MCP server using server.tool, providing name, description, schema, and handler.
    server.tool('mcp_email_send', "发送邮件", param, async (param) => { log(JSON.stringify(param)) // 调用EmailService发送邮件 const emailService = new EmailService(); const result = await emailService.sendEmail(param); log(JSON.stringify(result)) return { content: [ { type: "text", text: JSON.stringify(result, null, 2) } ] }; })
  • The EmailService.sendEmail helper method that implements the actual email sending logic using nodemailer, handling SMTP configuration, sending the email, and returning success/failure status.
    async sendEmail(param: EmailSendParam): Promise<{success: boolean, message: string}> { try { // 创建邮件传输器 const transporter = nodemailer.createTransport({ host: param.host, port: param.port, secure: true, // 使用SSL auth: { user: param.from, pass: param.fromPassword }, tls: { rejectUnauthorized: false // 允许使用自签名证书 } }); // 邮件选项 const mailOptions = { from: param.from, to: param.to, subject: param.subject, html: param.body }; // 发送邮件 const info = await transporter.sendMail(mailOptions); console.log(`[${new Date().toISOString()}] 邮件发送成功!MessageID: ${info.messageId}`); return { success: true, message: `邮件发送成功,MessageID: ${info.messageId}` }; } catch (error) { console.error(`[${new Date().toISOString()}] 邮件发送失败: ${error instanceof Error ? error.message : String(error)}`); return { success: false, message: `邮件发送失败: ${error instanceof Error ? error.message : String(error)}` }; } }

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

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