Skip to main content
Glama
shuakami

Mail MCP Tool

by shuakami

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()
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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