---
title: "Connect Mailtrap to ChatGPT: Manage email domains and sending stats"
slug: connect-mailtrap-to-chatgpt-manage-email-domains-and-sending-stats
date: 2026-07-07
author: Uday Gajavalli
categories: ["AI & Agents"]
excerpt: "Learn how to connect Mailtrap to ChatGPT using Truto's managed MCP server. Step-by-step guide to generating domains, tracking stats, and securely automating email ops."
tldr: "Connect Mailtrap to ChatGPT via a Truto MCP Server to manage email domains, verify DNS, and analyze delivery stats. This guide covers setup, secure access controls, and real-world AI tool-calling workflows."
canonical: https://truto.one/blog/connect-mailtrap-to-chatgpt-manage-email-domains-and-sending-stats/
---

# Connect Mailtrap to ChatGPT: Manage email domains and sending stats


You want to connect Mailtrap to ChatGPT so your AI agents can manage sending domains, audit delivery stats, and control email suppressions using natural language. If your team uses Claude, check out our guide on [connecting Mailtrap to Claude](https://truto.one/connect-mailtrap-to-claude-handle-contacts-lists-and-delivery-data/) or explore our broader architectural overview on [connecting Mailtrap to AI Agents](https://truto.one/connect-mailtrap-to-ai-agents-automate-email-logs-and-suppressions/).

Giving a Large Language Model (LLM) read and write access to your core email infrastructure is a complex engineering challenge. You are exposing critical systems - like domain verification, DNS record generation, and compliance information - directly to an AI agent. You either spend weeks building, hosting, and maintaining a custom integration layer, or you use a managed infrastructure layer that handles the boilerplate for you.

This guide breaks down exactly how to use Truto to generate a secure, managed [Model Context Protocol (MCP) server](https://truto.one/what-is-mcp-and-mcp-servers-and-how-do-they-work/) for Mailtrap, connect it natively to ChatGPT, and execute complex email administration workflows using natural language.

## The Engineering Reality of the Mailtrap API

A custom MCP server is a self-hosted integration layer that translates an LLM's tool calls into REST API requests. While the open MCP standard provides a predictable way for models to discover tools over JSON-RPC 2.0, the reality of implementing it against vendor APIs is painful. If you decide to [build a custom MCP server](https://truto.one/the-hands-on-guide-to-building-mcp-servers-for-ai-agents-2026/) for Mailtrap, you own the entire API lifecycle. 

Here are the specific integration challenges that break standard CRUD assumptions when working with Mailtrap:

### The Domain Verification and Compliance Maze
Creating a sending domain in Mailtrap is not a single API call. It is a multi-step orchestration process. When you create a domain, Mailtrap returns an array of specific DNS records (SPF, DKIM, DMARC) that must be added to your registrar. Furthermore, your domain will not be fully activated until you complete a compliance check, which requires pushing a strictly formatted payload to a secondary compliance endpoint. If your MCP server does not expose these endpoints cohesively, the LLM will fail to complete the setup process and leave domains in an unverified state.

### Strict Rate Limits and the IETF Spec
Mailtrap enforces aggressive rate limits on sensitive endpoints. For example, the suppressions list is capped at exactly 10 requests per minute per account. When this limit is exceeded, Mailtrap returns an HTTP 429 Too Many Requests error. Truto handles this by passing the error directly to the caller, normalizing the upstream rate limit information into standardized headers (`ratelimit-limit`, `ratelimit-remaining`, `ratelimit-reset`) per the IETF specification. We do not automatically retry or absorb rate limit errors. Your AI framework is responsible for reading these headers and executing exponential backoff, preventing the LLM from hallucinating a successful tool execution.

### Cursor-Based Pagination for Bulk Records
When an LLM requests the suppression list or email logs, it cannot ingest 10,000 records at once. Mailtrap uses cursor-based pagination utilizing a `last_id` parameter. The MCP server must dynamically inject pagination schemas into the tool definitions, explicitly instructing the LLM to pass cursor values back unchanged to fetch the next set of records. If the server attempts to buffer or cache the entire payload in memory, it will quickly exhaust resources and crash the connection.

## Generating the Mailtrap MCP Server

Instead of hardcoding tool definitions, Truto derives them dynamically from the integration's documented API resources. This means the MCP tools always match the current Mailtrap API schema. 

Every MCP server is scoped to a single connected Mailtrap instance and protected by a cryptographic token. You can generate this server URL through the Truto dashboard or programmatically via the API.

### Method 1: Via the Truto UI

For internal tooling and quick deployments, you can generate the MCP server directly from your dashboard:

1. Navigate to the **Integrated Accounts** page in your Truto environment.
2. Select your connected Mailtrap account.
3. Click the **MCP Servers** tab.
4. Click **Create MCP Server**.
5. Select your desired configuration (e.g., restrict to `read` methods only, or apply specific tags).
6. Copy the generated MCP server URL (it will look like `https://api.truto.one/mcp/abc123def456...`).

### Method 2: Via the Truto API

For platform teams embedding AI directly into their products, you can generate MCP servers programmatically. Make a `POST` request to the `/integrated-account/:id/mcp` endpoint using your Truto API key.

```bash
curl -X POST https://api.truto.one/integrated-account/{integrated_account_id}/mcp \
  -H "Authorization: Bearer <YOUR_TRUTO_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Mailtrap Admin Agent",
    "config": {
      "methods": ["read", "write", "custom"]
    },
    "expires_at": "2026-12-31T23:59:59Z"
  }'
```

The API securely provisions the token infrastructure and returns a payload containing the ready-to-use URL:

```json
{
  "id": "mcp_8f7e6d5c4b3a2",
  "name": "Mailtrap Admin Agent",
  "config": {
    "methods": ["read", "write", "custom"]
  },
  "expires_at": "2026-12-31T23:59:59.000Z",
  "url": "https://api.truto.one/mcp/a1b2c3d4e5f6g7h8i9j0"
}
```

## Connecting the MCP Server to ChatGPT

Once you have your Truto MCP server URL, you must register it with your AI framework. We will look at both the native ChatGPT configuration and the standard JSON configuration used by broader MCP clients.

### Method A: Via the ChatGPT UI

OpenAI natively supports [remote MCP connectors](https://truto.one/bring-100-custom-connectors-to-chatgpt-with-superai-by-truto/) on Pro, Plus, Business, Enterprise, and Education accounts.

1. Open ChatGPT and navigate to **Settings -> Apps -> Advanced settings**.
2. Toggle **Developer mode** on (MCP support requires this flag).
3. Under the **MCP servers / Custom connectors** section, click to add a new server.
4. **Name:** Enter a recognizable label (e.g., "Mailtrap Truto Server").
5. **Server URL:** Paste the Truto MCP URL you generated in the previous step.
6. Save the configuration.

ChatGPT will immediately perform a JSON-RPC handshake with the Truto endpoint, pull the auto-generated Mailtrap tools, and make them available to your agent.

### Method B: Via Manual Config File

If you are using Claude Desktop, Cursor, or a custom LangChain/LangGraph agent, you manage connections using a standardized `mcp.json` file. Because Truto provides a remote HTTPS endpoint, you use the official Server-Sent Events (SSE) adapter.

Add the following block to your MCP configuration file:

```json
{
  "mcpServers": {
    "mailtrap_admin": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-sse",
        "https://api.truto.one/mcp/a1b2c3d4e5f6g7h8i9j0"
      ]
    }
  }
}
```

## Mailtrap Hero Tools

When the LLM connects to the MCP server, it dynamically discovers tools mapped directly to the Mailtrap REST API. Below are the highest-leverage operations for email administration.

### list_all_mailtrap_domains
Retrieves all Mailtrap sending domains and their verification status. This is the primary discovery tool for auditing your email infrastructure. It returns the domain ID, compliance status, DNS records, tracking settings, and alert configurations.

**Contextual usage notes:** The AI uses this tool to audit which domains are missing DNS verification or failing compliance checks. It is usually the first tool called before attempting to update tracking settings.

> "Audit our Mailtrap sending domains and list any that are currently failing DNS verification or compliance checks."

### create_a_mailtrap_domain
Provisions a new Mailtrap domain for email authentication. After creation, it returns the necessary DNS records (SPF, DKIM, DMARC) required to actually send email.

**Contextual usage notes:** Creating a domain requires a `domain_name` payload. The AI must parse the returned DNS records and present them cleanly to the user so they can update their registrar.

> "Create a new sending domain for transactional.ourcompany.com and give me the exact SPF and DKIM records I need to add to Route53."

### list_all_mailtrap_suppressions
Searches and retrieves suppressed email addresses. Suppressed addresses are hard bounces, spam complaints, or unsubscribes that Mailtrap blocks from receiving further email.

**Contextual usage notes:** This tool utilizes cursor-based pagination. Due to the strict 10 requests per minute limit, the AI must handle this tool carefully and avoid aggressive polling. It requires admin-level access.

> "Pull the list of recent suppressions for our primary marketing stream and check if any internal company email addresses are on the list."

### list_all_mailtrap_stats
Aggregates Mailtrap account sending statistics (delivery, bounce, open, click, and spam counts). It mirrors the data shown in the Mailtrap Stats dashboard.

**Contextual usage notes:** Requires `start_date` and `end_date` query parameters. The AI can slice this data by domain, sending stream, category, and Email Service Provider (ESP) to diagnose delivery drops.

> "Show me the delivery and bounce rates for our transactional stream over the last 7 days. Did our bounce rate spike over the weekend?"

### get_single_mailtrap_email_log_by_id
Fetches the metadata for a specific email message log by its message ID, providing exact timestamps for when an email was created and sent.

**Contextual usage notes:** This is an essential debugging tool when a customer complains they did not receive a password reset email. The AI requires the exact `message_id` to query this endpoint.

> "Look up the email log for message ID 8f7e6d5c-4b3a-2a1b and tell me exactly when Mailtrap processed it."

### create_a_mailtrap_webhook
Provisions a new Mailtrap webhook to stream event data (like opens, clicks, or bounces) to external URLs. 

**Contextual usage notes:** The LLM must provide the target `url` and `webhook_type`. This allows the AI to programmatically configure data pipelines without manual dashboard intervention.

> "Create a new webhook to stream all bounce and spam complaint events to https://api.ourcompany.com/webhooks/mailtrap."

To see the full schema, query parameters, and complete inventory of available proxy endpoints, visit the [Mailtrap integration page](https://truto.one/integrations/detail/mailtrap).

## Workflows in Action

To understand how an AI agent interacts with the flat input namespace of the MCP server, let us look at real-world administration scenarios. The Truto MCP router automatically splits the AI's arguments into query parameters and body parameters based on the integration schema.

### Scenario 1: Domain Setup and Compliance Verification

When standing up a new product line, DevOps teams need to quickly register a new sending domain, extract the DNS records, and submit company information for Mailtrap's strict compliance checks.

> "We need to set up 'notifications.newproduct.com' in Mailtrap. Create the domain, output the DNS records as a markdown table, and then submit our company info (Acme Corp, San Francisco, US) to pass the compliance check."

**Step-by-step execution:**
1. **Create Domain:** The agent calls `create_a_mailtrap_domain` passing `domain_name: "notifications.newproduct.com"`.
2. **Extract Data:** The agent reads the JSON response, isolating the `dns_records` array (SPF, DKIM, DMARC).
3. **Submit Compliance:** The agent takes the newly returned `domain_id` and calls `create_a_mailtrap_domain_company_info`, formatting the user's provided location data into the required body schema.
4. **Final Output:** The agent formats the DNS records into a markdown table and confirms compliance submission is pending.

```mermaid
sequenceDiagram
  participant User as User
  participant LLM as ChatGPT
  participant MCP as Truto MCP Server
  participant Upstream as Mailtrap API

  User->>LLM: "Set up notifications.newproduct.com..."
  LLM->>MCP: Call create_a_mailtrap_domain
  MCP->>Upstream: POST /api/v1/domains
  Upstream-->>MCP: Domain ID + DNS Records
  MCP-->>LLM: JSON Tool Response
  LLM->>MCP: Call create_a_mailtrap_domain_company_info
  MCP->>Upstream: POST /api/v1/domains/{id}/company_info
  Upstream-->>MCP: Compliance pending status
  MCP-->>LLM: JSON Tool Response
  LLM-->>User: Markdown table of DNS records
```

### Scenario 2: Diagnosing Delivery Drops

If the customer success team reports a spike in users failing to receive order confirmations, the AI agent can be deployed to investigate the root cause.

> "Check our delivery stats for the last 48 hours. If the bounce rate is above 2%, pull the recent suppressions list and see if our major clients are hard bouncing."

**Step-by-step execution:**
1. **Fetch Stats:** The agent calls `list_all_mailtrap_stats` using calculated ISO dates for `start_date` and `end_date`.
2. **Analyze Rates:** The agent calculates the bounce rate from the returned metrics.
3. **Conditional Logic:** Seeing a bounce rate of 4.5%, the agent decides to proceed.
4. **Fetch Suppressions:** The agent calls `list_all_mailtrap_suppressions`.
5. **Pagination Check:** If the list is large, the agent checks for a `last_id` cursor and passes it back unchanged to fetch the next page.
6. **Final Output:** The agent summarizes the root cause, identifying specific client domains that are triggering hard bounces.

## Security and Access Control

Exposing your core email infrastructure to an LLM requires strict boundary enforcement. Truto MCP servers implement expiration mechanisms and granular filtering at the infrastructure level.

*   **Method Filtering (`config.methods`):** Restrict an MCP server to read-only operations by passing `["read"]` during creation. This allows the AI to analyze stats and suppressions but physically prevents it from creating domains or updating webhooks.
*   **Tag Filtering (`config.tags`):** Filter the available tools by functional area. You can restrict an agent to only tools tagged with `"stats"`, hiding all user and domain administration capabilities.
*   **Dual Authentication (`require_api_token_auth`):** By default, possessing the MCP token URL grants access. By setting `require_api_token_auth: true`, Truto enforces a dual-middleware layer. The caller must provide the MCP URL *and* a valid Truto session or API Bearer token, ensuring only authenticated human team members can execute the tools.
*   **Automatic Expiration (`expires_at`):** Schedule temporary access for contractors or temporary AI agents. Once the ISO datetime is reached, the underlying Key-Value storage automatically evicts the token, and a durable worker permanently destroys the credentials.

:::cta{buttonText="Talk to us" buttonUrl="https://cal.com/truto/partner-with-truto"} 
Want to securely connect your AI agents to Mailtrap and 100+ other SaaS APIs? Let's talk architecture.
:::

Connecting ChatGPT to Mailtrap transforms how IT and DevOps teams manage email infrastructure. By utilizing an auto-generated MCP server, you bypass the friction of custom authentication layers, complex JSON schema mapping, and brittle API integrations. You enforce strict security boundaries at the edge while giving your models the precise tools they need to resolve tickets, provision domains, and audit compliance workflows securely.
