Overview
Complete API documentation for the Mailtrap email platform
Welcome to the Mailtrap API documentation. Our APIs provide comprehensive access to email sending, testing, contact management, and account administration features.
The Mailtrap API follows REST principles. Authenticated users can interact with any endpoint using standard HTTP methods. All requests must be sent over HTTPS, as TLS encryption is enforced.
LLM & AI Agent Integration
For AI assistants and coding agents: a structured, LLM-optimized version of this documentation is available at https://docs.mailtrap.io/llms.txt. It includes API routing instructions, endpoint summaries, and integration guidance formatted for accurate code generation.
Documentation structure
The API documentation is organized into the following sections:
Email Sending
Endpoints to send transactional and bulk (promotional) emails, as well as manage sending domains, suppressions, and delivery statistics.
Templates
Endpoints to manage email templates used for email sending, email sandbox, and campaigns.
Email Marketing
Endpoints to manage contacts, send email campaigns, and get campaign stats.
Email Sandbox
Endpoints for testing and inspecting emails in a safe environment. Note: Email Sending and Email Sandbox use different base URLs.
Account Management
Endpoints for programmatic management of account details and access permissions.
Quick Start
Get API Credentials
Navigate to API Tokens.
Generate a new API token with the required permissions.
Install an SDK
Choose an SDK for your programming language, or use the API directly with cURL.
Supported SDKs:
npm install mailtrappip install mailtrapcomposer require railsware/mailtrap-phpgem install mailtrap<dependency>
<groupId>io.mailtrap</groupId>
<artifactId>mailtrap-java</artifactId>
<version>2.0.0</version>
</dependency>The .NET SDK is available via GitHub Packages. First, add the GitHub source:
dotnet nuget add source https://nuget.pkg.github.com/mailtrap/index.json \
--name github-mailtrap \
--username GITHUB_USERNAME \
--password GITHUB_PATThen install the package:
dotnet add package Mailtrap -s github-mailtrapgo get github.com/mailtrap/mailtrap-goAdd the SDK to your mix.exs dependencies:
def deps do
[
{:mailtrap, "~> 0.2.0"}
]
endThen run:
mix deps.getSend your first email
Below are minimal examples for sending an email:
import { MailtrapClient } from "mailtrap";
const mailtrap = new MailtrapClient({
token: process.env.MAILTRAP_API_KEY, // You can create your API key here https://mailtrap.io/settings/api-tokens
});
mailtrap
.send({
from: { name: "Mailtrap Test", email: "sender@example.com" },
to: [{ email: "recipient@example.com" }],
subject: "Hello from Mailtrap Node.js",
text: "Plain text body",
})
.then(console.log)
.catch(console.error);import mailtrap as mt
API_TOKEN = "<YOUR_API_TOKEN>" # your API key here https://mailtrap.io/settings/api-tokens
client = mt.MailtrapClient(token=API_TOKEN)
# Create mail object
mail = mt.Mail(
sender=mt.Address(email="sender@example.com", name="John Smith"),
to=[mt.Address(email="recipient@example.com")],
subject="You are awesome!",
text="Congrats for sending test email with Mailtrap!",
)
client.send(mail)Email Sending Options
Transactional emails
Best suited for real-time, one-to-one emails triggered by user actions, such as:
Order confirmations
Password resets
Account notifications
System alerts
Welcome emails
Endpoint:
https://send.api.mailtrap.io/api/send
Bulk stream
Optimized for high-volume marketing and promotional campaigns, including:
Newsletters
Promotional campaigns
Product announcements
Marketing emails
Endpoint:
https://bulk.api.mailtrap.io/api/send
Batch sending
Send up to 500 emails in a single API call. Useful for:
Personalized notifications
Event invitations
Account updates
Targeted campaigns
Endpoints:
Transactional:
https://send.api.mailtrap.io/api/batchBulk:
https://bulk.api.mailtrap.io/api/batch
Testing with Email Sandbox
Before going to production, test your email integration using Email Sandbox. All official SDKs support Sandbox mode and allow you to easily switch between testing and production environments.
We recommend using environment variables to manage the switch between Sandbox and Production modes.
How Sandbox works
Sandbox emails are captured in your test inbox instead of being delivered to real recipients.
To find your Sandbox ID:
Open your Sandbox inbox in Mailtrap.
Copy the ID from the inbox URL.
Example: https://mailtrap.io/sandboxes/2564102
Sandbox ID: 2564102
Last updated
Was this helpful?

