Skip to main content
Glama

sendBulkMail

Send personalized emails to multiple recipients at once using the Mail MCP Tool. Manage recipients, subject lines, content, and attachments for efficient email campaigns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
toYes
ccNo
bccNo
subjectYes
textNo
htmlNo
attachmentsNo

Implementation Reference

  • Registration of the sendBulkMail MCP tool, including input schema and the complete inline handler function that batches recipients into groups of 10, sends via mailService.sendMail with delays, and reports success/failure counts.
    "sendBulkMail", { to: z.array(z.string()), cc: z.array(z.string()).optional(), bcc: z.array(z.string()).optional(), subject: z.string(), text: z.string().optional(), html: z.string().optional(), attachments: z.array( z.object({ filename: z.string(), content: z.union([z.string(), z.instanceof(Buffer)]), contentType: z.string().optional() }) ).optional() }, async (params) => { try { if (!params.text && !params.html) { return { content: [ { type: "text", text: `邮件内容不能为空,请提供text或html参数。` } ] }; } console.log(`开始群发邮件,收件人数量: ${params.to.length}`); const results = []; let successCount = 0; let failureCount = 0; // 分批发送,每批最多10个收件人 const batchSize = 10; for (let i = 0; i < params.to.length; i += batchSize) { const batch = params.to.slice(i, i + batchSize); try { const result = await this.mailService.sendMail({ to: batch, cc: params.cc, bcc: params.bcc, subject: params.subject, text: params.text, html: params.html, attachments: params.attachments }); results.push(result); if (result.success) { successCount += batch.length; } else { failureCount += batch.length; } // 添加延迟,避免邮件服务器限制 if (i + batchSize < params.to.length) { await new Promise(resolve => setTimeout(resolve, 1000)); } } catch (error) { console.error(`发送批次 ${i / batchSize + 1} 时出错:`, error); failureCount += batch.length; } } return { content: [ { type: "text", text: `群发邮件完成。\n成功: ${successCount}个收件人\n失败: ${failureCount}个收件人\n\n${ failureCount > 0 ? '部分邮件发送失败,可能是由于邮件服务器限制或收件人地址无效。' : '' }` } ] }; } catch (error) { return { content: [ { type: "text", text: `群发邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } } );
  • Handler function implementing bulk mail sending: validates content, batches recipients (max 10 per batch), sends each batch via mailService.sendMail with 1s delay between batches, tracks success/failure counts, returns summary.
    async (params) => { try { if (!params.text && !params.html) { return { content: [ { type: "text", text: `邮件内容不能为空,请提供text或html参数。` } ] }; } console.log(`开始群发邮件,收件人数量: ${params.to.length}`); const results = []; let successCount = 0; let failureCount = 0; // 分批发送,每批最多10个收件人 const batchSize = 10; for (let i = 0; i < params.to.length; i += batchSize) { const batch = params.to.slice(i, i + batchSize); try { const result = await this.mailService.sendMail({ to: batch, cc: params.cc, bcc: params.bcc, subject: params.subject, text: params.text, html: params.html, attachments: params.attachments }); results.push(result); if (result.success) { successCount += batch.length; } else { failureCount += batch.length; } // 添加延迟,避免邮件服务器限制 if (i + batchSize < params.to.length) { await new Promise(resolve => setTimeout(resolve, 1000)); } } catch (error) { console.error(`发送批次 ${i / batchSize + 1} 时出错:`, error); failureCount += batch.length; } } return { content: [ { type: "text", text: `群发邮件完成。\n成功: ${successCount}个收件人\n失败: ${failureCount}个收件人\n\n${ failureCount > 0 ? '部分邮件发送失败,可能是由于邮件服务器限制或收件人地址无效。' : '' }` } ] }; } catch (error) { return { content: [ { type: "text", text: `群发邮件时发生错误: ${error instanceof Error ? error.message : String(error)}` } ] }; } }
  • Input schema using Zod: required 'to' (recipients array), 'subject'; optional 'cc', 'bcc', 'text', 'html', 'attachments' (array of filename/content/contentType).
    { to: z.array(z.string()), cc: z.array(z.string()).optional(), bcc: z.array(z.string()).optional(), subject: z.string(), text: z.string().optional(), html: z.string().optional(), attachments: z.array( z.object({ filename: z.string(), content: z.union([z.string(), z.instanceof(Buffer)]), contentType: z.string().optional() }) ).optional()

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/shuakami/mcp-mail'

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