Email for Agents

Email infrastructure for AI Agents

Give your AI agent a complete email layer. Send emails, receive replies, test output safely, and manage email workflows through a single API and MCP server.

// Claude or Cursor
{
  "mcpServers": {
    "mailtrap": {
      "command": "npx",
      "args": ["-y", "mcp-mailtrap"],
      "env": {
        "MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
        "DEFAULT_FROM_EMAIL": "your_sender@example.com",
        "MAILTRAP_ACCOUNT_ID": "your_account_id",
        "MAILTRAP_SANDBOX_ID": "your_sandbox_id"
      }
    }
  }
}

// VS Code
{
  "mcp": {
    "servers": {
      "mailtrap": {
        "command": "npx",
        "args": ["-y", "mcp-mailtrap"],
        "env": {
          "MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
          "DEFAULT_FROM_EMAIL": "your_sender@example.com",
          "MAILTRAP_ACCOUNT_ID": "your_account_id",
          "MAILTRAP_SANDBOX_ID": "your_sandbox_id"
        }
      }
    }
  }
}

// Claude Code (asdf)
{
  "mcpServers": {
    "mailtrap": {
      "command": "/Users/<username>/.asdf/shims/npx",
      "args": ["-y", "mcp-mailtrap"],
      "env": {
        "PATH": "/Users/<username>/.asdf/shims:/usr/bin:/bin",
        "ASDF_DIR": "/opt/homebrew/opt/asdf/libexec",
        "ASDF_DATA_DIR": "/Users/<username>/.asdf",
        "ASDF_NODEJS_VERSION": "22.14.0",
        "MAILTRAP_API_TOKEN": "your_mailtrap_api_token",
        "DEFAULT_FROM_EMAIL": "your_sender@example.com",
        "MAILTRAP_ACCOUNT_ID": "your_account_id",
        "MAILTRAP_SANDBOX_ID": "your_sandbox_id"
      }
    }
  }
}

// MCP Bundle (MCPB)
Download the .mcpb file from GitHub Releases and open it in Claude Desktop.

One API for the complete agent email lifecycle

Test outbound email, receive inbound messages, trigger workflows, and send replies – all via Mailtrap API.

curl -X POST https://send.api.mailtrap.io/api/send \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{ "from": { "email": "agent@yourdomain.com" }, "to": [{ "email": "recipient@example.com" }], "subject": "Your receipt", "text": "Thanks for your order." }'

Everything your agent needs to work with email

Sending API & SMTP

Send transactional and bulk email through the REST API or SMTP. Keep the two on separate sending streams, use templates, and rely on official SDKs in your agent’s language.

Hosted agent inboxes

Spin up an inbox per agent with no DNS setup. Every incoming message arrives as parsed JSON via webhook and the Messages API, with attachments as download links.

In-thread replies

Answer inbound email with a single API call. Mailtrap sets the threading headers and sender address, and your agent can fetch the full conversation as context.

Sandbox testing

Point your agent at Email Sandbox during development. It captures every email instead of delivering it, so you can check content, headers, attachments, spam score and HTML first.
Mailtrap provides actively maintained SDKs

MCP server for agents

Connect Claude, Cursor, VS Code and other MCP clients. Over 130 tools cover sending, inbound inboxes and messages, Sandbox and templates, all through natural-language requests.
Mailtrap provides actively maintained SDKs

Official SDKs & CLI

Official SDKs for Node.js, PHP, Python, Ruby, Java and .NET. The CLI runs sending, Sandbox and account tasks from the terminal, with JSON output for scripts and agents.

Built for teams adding email to AI agents and workflows

Whether you're building a coding agent, an AI app or an assistant, Mailtrap gives it one email layer, through the API and the MCP server.

  • Engineering teams

    Engineering teams

    Add inbound email to your product without running email infrastructure.

    • Create inboxes programmatically
    • Receive parsed email as structured JSON
    • Store messages, attachments, and conversation history
    • Trigger application logic from incoming email
  • AI builders & enthusiasts

    AI builders & enthusiasts

    Give every agent its own inbox and full email context.

    • Create inboxes for agents, assistants, and copilots
    • Turn incoming email into agent events
    • Access complete conversation threads
    • Reply in-thread through the API
  • Automation & ops builders

    Automation & ops builders

    Use email as a trigger for workflows and business processes.

    • Start workflows when emails arrive
    • Forward messages to the right team
    • Process invoices, approvals, and notifications
    • Connect email to n8n, Make, or custom automations

What teams build with Mailtrap and AI agents

How teams use Mailtrap with their agents

AI Support Agent

AI Support Agent

Receive support emails, create tickets, draft replies.

AI Receptionists

AI Receptionists

Read appointment requests, answer common questions, and schedule meetings.

GitHub Automation

GitHub Automation

Convert alert emails into issues and tasks.

Invoice Processing

Invoice Processing

Extract PDFs and trigger accounting workflows.

AI agent quality testing

AI agent quality testing

Inspect every email your agent drafts and catch the bad ones before a customer sees them.

Inbound reply testing

Inbound reply testing

Test how your agent replies to inbound emails before those replies ever go out.

Agent-sent notifications

Agent-sent notifications

Your agent sends receipts, alerts and follow-ups through the Email API.

Frequently Asked Questions

  • How do you give an AI agent its own programmable email inbox?

    Call the Mailtrap API to create an inbox, then register a webhook URL where your agent gets notified when new mail arrives. Start on a Mailtrap-hosted address with no MX records, no DNS, and no mail server to set up, or connect your own custom domain when you’re ready for production. The moment an email lands, your agent gets a webhook notification and can fetch the fully parsed message from the Messages API. Create or delete inboxes programmatically for each agent, project, or session.

  • Why give an agent a dedicated inbox instead of access to Gmail?

    OAuth into a personal Gmail account hands your agent someone’s entire mailbox, with all the privacy, scope, and security questions that it brings, and it breaks the moment a token is revoked. A dedicated agent inbox is isolated, scoped to addresses you control, and provisioned per agent or project. Your agent only ever sees emails meant for it, and you can spin inboxes up or tear them down without touching anyone’s personal account.

  • Do I need a custom domain or DNS setup to receive email?

    No, not to get started. A Mailtrap-hosted inbox works the moment you create it, with nothing to add in DNS and no MX records to configure. When you’re ready for production, connect your own custom domain and keep the same API and webhooks. Replies go out the same way in both cases, with a single API call.

  • Can my agent reply to inbound emails?

    Yes. Replying is part of the same API, so your agent answers in-thread with a single API call and the conversation flows both ways. On a Mailtrap-hosted inbox, replies are capped at 20 in total; connect your own custom domain and that limit goes away.

  • What is an email sandbox for AI agents?

    It’s a safe, Mailtrap-hosted environment that captures the email your AI agent sends instead of delivering it. Your agent sends exactly as it would in production but every message lands in the sandbox, where you can read the content, headers, and attachments, check the spam score, and validate the HTML. Nothing reaches a real recipient, so you can test what an agent generates without any risk of emailing a customer by mistake.

  • How do I add a human-in-the-loop approval step to my AI email workflow?

    A common approach is to have your AI agent generate emails in Mailtrap Sandbox first instead of sending them directly.

    You can review the message in the Mailtrap UI or retrieve its content, spam score, HTML checks, and other analysis via API. If changes are needed, your AI agent can revise the draft and send an updated version to Sandbox for another review cycle.

    Once the email looks right, switch to Mailtrap’s sending endpoint (or the Inbound Reply API for inbound conversations) to deliver the final message. This creates a simple human approval workflow without changing your email generation logic.