Skip to main content
Glama
mailtrap

MCP Mailtrap Server

Official
by mailtrap

send-sandbox-email

Send test emails to a sandbox inbox for safe email testing without delivering to actual recipients. Verify email formatting, content, and functionality before production use.

Instructions

Send an email in sandbox mode to a test inbox without delivering to your recipients

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fromYesEmail address of the sender
toYesEmail addresses (comma-separated or single)
subjectYesEmail subject line
ccNoOptional CC recipients
bccNoOptional BCC recipients
categoryNoOptional email category for tracking
textNoEmail body text
htmlNoOptional HTML version of the email body

Implementation Reference

  • The handler function for send-sandbox-email tool. Sends an email using Mailtrap sandbox client to a test inbox.
    async function sendSandboxEmail({
      from,
      to,
      subject,
      text,
      cc,
      bcc,
      category,
      html,
    }: SendSandboxEmailRequest): Promise<{ content: any[]; isError?: boolean }> {
      try {
        const { MAILTRAP_TEST_INBOX_ID } = process.env;
    
        if (!MAILTRAP_TEST_INBOX_ID) {
          throw new Error(
            "MAILTRAP_TEST_INBOX_ID environment variable is required for sandbox mode"
          );
        }
    
        if (!html && !text) {
          throw new Error("Either HTML or TEXT body is required");
        }
    
        // Use provided 'from' email or fall back to DEFAULT_FROM_EMAIL
        const fromEmail = from || DEFAULT_FROM_EMAIL;
    
        if (!fromEmail) {
          throw new Error(
            "No 'from' email provided and no 'DEFAULT_FROM_EMAIL' email set"
          );
        }
    
        // Check if sandbox client is available
        if (!sandboxClient) {
          throw new Error(
            "Sandbox client is not available. Please set MAILTRAP_TEST_INBOX_ID environment variable."
          );
        }
    
        const fromAddress: Address = {
          email: fromEmail,
        };
    
        // Parse and validate email addresses from the 'to' string
        const toEmails = to
          .split(",")
          .map((email) => email.trim())
          .filter((email) => email.length > 0)
          .filter((email) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email));
    
        if (toEmails.length === 0) {
          throw new Error("No valid email addresses provided in 'to' field");
        }
    
        const toAddresses: Address[] = toEmails.map((email) => ({ email }));
    
        const emailData: Mail = {
          from: fromAddress,
          to: toAddresses,
          subject,
          text,
          html,
          category,
        };
    
        if (cc && cc.length > 0) emailData.cc = cc.map((email) => ({ email }));
        if (bcc && bcc.length > 0) emailData.bcc = bcc.map((email) => ({ email }));
    
        const response = await sandboxClient.send(emailData);
    
        return {
          content: [
            {
              type: "text",
              text: `Sandbox email sent successfully to ${toEmails.join(
                ", "
              )}.\nMessage IDs: ${response.message_ids.join(", ")}\nStatus: ${
                response.success ? "Success" : "Failed"
              }`,
            },
          ],
        };
      } catch (error) {
        console.error("Error sending sandbox email:", error);
    
        const errorMessage = error instanceof Error ? error.message : String(error);
    
        return {
          content: [
            {
              type: "text",
              text: `Failed to send sandbox email: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    }
    
    export default sendSandboxEmail;
  • Input schema definition for the send-sandbox-email tool parameters.
    const sendSandboxEmailSchema = {
      type: "object",
      properties: {
        from: {
          type: "string",
          format: "email",
          description: "Email address of the sender",
        },
        to: {
          type: "string",
          minLength: 1,
          description: "Email addresses (comma-separated or single)",
        },
        subject: {
          type: "string",
          description: "Email subject line",
        },
        cc: {
          type: "array",
          items: {
            type: "string",
            format: "email",
          },
          description: "Optional CC recipients",
        },
        bcc: {
          type: "array",
          items: {
            type: "string",
            format: "email",
          },
          description: "Optional BCC recipients",
        },
        category: {
          type: "string",
          description: "Optional email category for tracking",
        },
        text: {
          type: "string",
          description: "Email body text",
        },
        html: {
          type: "string",
          description: "Optional HTML version of the email body",
        },
      },
      required: ["from", "to", "subject"],
      additionalProperties: false,
    };
    
    export default sendSandboxEmailSchema;
  • src/server.ts:82-91 (registration)
    Registration of the send-sandbox-email tool in the tools array, linking schema and handler.
    {
      name: "send-sandbox-email",
      description:
        "Send an email in sandbox mode to a test inbox without delivering to your recipients",
      inputSchema: sendSandboxEmailSchema,
      handler: sendSandboxEmail,
      annotations: {
        destructiveHint: false,
      },
    },
Behavior4/5

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

The description adds valuable behavioral context beyond the annotations. While annotations only indicate destructiveHint=false (non-destructive), the description clarifies this is a sandbox/test mode where emails go to a test inbox rather than actual recipients. This provides crucial context about the tool's safety and testing purpose that annotations alone don't convey.

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 conveys all essential information: the action, the mode, the destination, and the key limitation. Every word earns its place with no redundancy or unnecessary elaboration.

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

Completeness4/5

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

For a tool with good annotations (destructiveHint=false) and complete schema coverage, the description provides appropriate context about the sandbox/testing nature. While there's no output schema, the description adequately explains what the tool does. It could slightly improve by mentioning what happens to sent emails (e.g., stored in test inbox for retrieval).

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?

With 100% schema description coverage, all parameters are already well-documented in the input schema. The description doesn't add any parameter-specific information beyond what's in the schema. This meets the baseline expectation when schema coverage is complete.

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

Purpose5/5

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

The description clearly states the specific action ('send an email'), the resource ('in sandbox mode'), and the key limitation ('without delivering to your recipients'). It effectively distinguishes this tool from the sibling 'send-email' tool by specifying the sandbox/testing nature of the operation.

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

Usage Guidelines5/5

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

The description explicitly states when to use this tool: 'in sandbox mode to a test inbox without delivering to your recipients.' This clearly indicates it's for testing purposes rather than actual email delivery, distinguishing it from the regular 'send-email' sibling tool. The context signals the existence of both sandbox and production email tools.

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/mailtrap/mailtrap-mcp'

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