Skip to main content
Glama
samihalawa

SMTP MCP Server

send-bulk-emails

Send emails to multiple recipients with rate limiting to manage delivery speed and prevent server overload. Supports HTML content, templates, and batch processing.

Instructions

Send emails in bulk to multiple recipients with rate limiting

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
recipientsYesArray of recipients
subjectYesEmail subject
bodyYesEmail body (HTML supported)
fromNoSender information. If not provided, the default SMTP user will be used.
ccNoArray of CC recipients
bccNoArray of BCC recipients
templateIdNoID of the email template to use. If not provided, the email will use the subject and body provided.
templateDataNoData to be used for template variable substitution
batchSizeNoNumber of emails to send in each batch (default: 10)
delayBetweenBatchesNoDelay between batches in milliseconds (default: 1000)
smtpConfigIdNoID of the SMTP configuration to use. If not provided, the default configuration will be used.

Implementation Reference

  • Executes the send-bulk-emails tool: constructs BulkEmailData from tool parameters and delegates to the sendBulkEmails core function.
    async function handleSendBulkEmails(parameters: any) {
      try {
        // Prepare the bulk email data
        const bulkEmailData: BulkEmailData = {
          recipients: parameters.recipients,
          subject: parameters.subject,
          body: parameters.body,
          from: parameters.from,
          cc: parameters.cc,
          bcc: parameters.bcc,
          templateId: parameters.templateId,
          templateData: parameters.templateData,
          batchSize: parameters.batchSize,
          delayBetweenBatches: parameters.delayBetweenBatches
        };
        
        // Send the bulk emails
        const result = await sendBulkEmails(bulkEmailData, parameters.smtpConfigId);
        
        return {
          success: result.success,
          totalSent: result.totalSent,
          totalFailed: result.totalFailed,
          failures: result.failures,
          message: result.message
        };
      } catch (error) {
        logToFile('Error in handleSendBulkEmails:');
        logToFile(error instanceof Error ? error.message : 'Unknown error');
        return {
          success: false,
          totalSent: 0,
          totalFailed: parameters.recipients?.length || 0,
          message: error instanceof Error ? error.message : 'Unknown error'
        };
      }
    }
  • Core bulk email sending logic: batches recipients, creates individual EmailData per recipient (with template personalization), sends via sendEmail, tracks stats and failures.
    export async function sendBulkEmails(data: BulkEmailData, smtpConfigId?: string): Promise<{
      success: boolean;
      totalSent: number;
      totalFailed: number;
      failures?: { email: string; error: string }[];
      message?: string;
    }> {
      try {
        const { recipients, batchSize = 10, delayBetweenBatches = 1000 } = data;
        
        if (!recipients || recipients.length === 0) {
          return { 
            success: false, 
            totalSent: 0, 
            totalFailed: 0,
            message: 'No recipients provided'
          };
        }
        
        const failures: { email: string; error: string }[] = [];
        let totalSent = 0;
        
        // Process recipients in batches
        for (let i = 0; i < recipients.length; i += batchSize) {
          const batch = recipients.slice(i, i + batchSize);
          
          // Send emails to the batch (one by one to allow for individual template processing)
          const promises = batch.map(async (recipient) => {
            try {
              // Create email data for single recipient using the bulk data
              const emailData: EmailData = {
                to: recipient,
                subject: data.subject,
                body: data.body,
                from: data.from,
                cc: data.cc,
                bcc: data.bcc,
                templateId: data.templateId,
                templateData: {
                  ...data.templateData,
                  email: recipient.email,
                  name: recipient.name || ''
                }
              };
              
              const result = await sendEmail(emailData, smtpConfigId);
              
              if (result.success) {
                totalSent++;
                return { success: true };
              } else {
                failures.push({ email: recipient.email, error: result.message || 'Unknown error' });
                return { success: false, error: result.message };
              }
            } catch (error) {
              failures.push({ 
                email: recipient.email, 
                error: error instanceof Error ? error.message : 'Unknown error' 
              });
              return { success: false, error };
            }
          });
          
          await Promise.all(promises);
          
          // If not the last batch, wait before processing the next batch
          if (i + batchSize < recipients.length) {
            await new Promise(resolve => setTimeout(resolve, delayBetweenBatches));
          }
        }
        
        return {
          success: totalSent > 0,
          totalSent,
          totalFailed: failures.length,
          failures: failures.length > 0 ? failures : undefined,
          message: `Successfully sent ${totalSent} out of ${recipients.length} emails`
        };
      } catch (error) {
        logToFile(`Error sending bulk emails: ${error}`);
        return { 
          success: false, 
          totalSent: 0, 
          totalFailed: data.recipients.length,
          message: error instanceof Error ? error.message : 'Unknown error sending bulk emails'
        };
      }
    } 
  • Input schema and metadata definition for the send-bulk-emails tool.
    "send-bulk-emails": {
      name: "send-bulk-emails",
      description: "Send emails in bulk to multiple recipients with rate limiting",
      inputSchema: {
        type: "object",
        properties: {
          recipients: {
            type: "array",
            items: {
              type: "object",
              properties: {
                email: { type: "string" },
                name: { type: "string" }
              },
              required: ["email"]
            },
            description: "Array of recipients"
          },
          subject: {
            type: "string",
            description: "Email subject"
          },
          body: {
            type: "string",
            description: "Email body (HTML supported)"
          },
          from: {
            type: "object",
            properties: {
              email: { type: "string" },
              name: { type: "string" }
            },
            description: "Sender information. If not provided, the default SMTP user will be used."
          },
          cc: {
            type: "array",
            items: {
              type: "object",
              properties: {
                email: { type: "string" },
                name: { type: "string" }
              },
              required: ["email"]
            },
            description: "Array of CC recipients"
          },
          bcc: {
            type: "array",
            items: {
              type: "object",
              properties: {
                email: { type: "string" },
                name: { type: "string" }
              },
              required: ["email"]
            },
            description: "Array of BCC recipients"
          },
          templateId: {
            type: "string",
            description: "ID of the email template to use. If not provided, the email will use the subject and body provided."
          },
          templateData: {
            type: "object",
            description: "Data to be used for template variable substitution"
          },
          batchSize: {
            type: "number",
            description: "Number of emails to send in each batch (default: 10)"
          },
          delayBetweenBatches: {
            type: "number",
            description: "Delay between batches in milliseconds (default: 1000)"
          },
          smtpConfigId: {
            type: "string",
            description: "ID of the SMTP configuration to use. If not provided, the default configuration will be used."
          }
        },
        required: ["recipients", "subject", "body"]
      }
    },
  • src/index.ts:59-62 (registration)
    Registers the send-bulk-emails tool (among others) by calling createToolDefinitions() and passing the tools record to setupRequestHandlers.
    const TOOLS = createToolDefinitions();
    
    // Setup request handlers
    await setupRequestHandlers(server, TOOLS);
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'rate limiting' which is useful context, but doesn't describe what happens on failure (partial sends?), authentication requirements, whether emails are queued or sent immediately, or what the response looks like. For a mutation tool with 11 parameters, this is insufficient.

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

Conciseness5/5

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

The description is a single, efficient sentence that states the core purpose and key behavioral constraint ('rate limiting'). Every word earns its place with zero waste or redundancy.

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

Completeness2/5

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

For a complex mutation tool with 11 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain the return value, error handling, prerequisites (like needing configured SMTP), or how it differs from the simpler 'send-email' sibling. The 'rate limiting' mention is helpful but insufficient for full contextual understanding.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. The baseline of 3 is appropriate when the schema does the heavy lifting, though the description could have explained the relationship between templateId/templateData and subject/body.

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

Purpose4/5

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

The description clearly states the action ('send emails in bulk') and resource ('to multiple recipients'), which distinguishes it from the sibling 'send-email' tool that likely sends to single recipients. However, it doesn't explicitly mention email content or how it differs from template-based sending, which is a minor gap.

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

Usage Guidelines2/5

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

The description mentions 'rate limiting' which provides some context about when to use it (for bulk operations with controlled pacing), but it doesn't explicitly guide when to choose this tool over 'send-email' or when to use templates vs. direct subject/body. No alternatives or exclusions are mentioned.

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/samihalawa/mcp-server-smtp'

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