codeOverview

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.

Documentation structure

The API documentation is organized into the following sections:

Email Sending

Endpoints to send transactional and bulkarrow-up-right (promotional) emails, as well as manage sending domains, suppressions, and delivery statistics.

Templates

Endpoints to manage email templatesarrow-up-right used for email sending, email sandbox, and campaigns.

Promotional

Endpoints to manage contactsarrow-up-right. Contacts can be used to run campaigns and set up automations.

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

1

Get API Credentials

  1. Generate a new API token with the required permissions.

circle-info

You must have a verified domainarrow-up-right to send emails.

Keep your API token secure and never expose it in client-side code.

2

Install an SDK

Choose an SDK for your programming language, or use the API directly with cURL.

Supported SDKs:

npm install mailtrap
3

Send 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/api-tokens
});

mailtrap
  .send({
    from: { name: "Mailtrap Test", email: "[email protected]" },
    to: [{ email: "[email protected]" }],
    subject: "Hello from Mailtrap Node.js",
    text: "Plain text body",
  })
  .then(console.log)
  .catch(console.error);

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/batch

  • Bulk: 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:

  1. Open your Sandbox inbox in Mailtrap.

  2. Copy the ID from the inbox URL.

Example: https://mailtrap.io/inboxes/2564102/messages Sandbox ID: 2564102

Last updated

Was this helpful?