API integration

Learn how to integrate the Mailtrap API and what you can test with it. It uses the REST protocol and can return calls in JSON or XML. Compatible with the majority of common programming languages.

In this article:

How Mailtrap API works

The Mailtrap API uses REST protocol and can return calls in JSON or XML data formats. It is compatible with the majority of common programming languages. 

Mailtrap supports the following HTTPs requests:

  •  POST to create a resource
  •  PATCH  to update a resource
  •  GET to get a resource or list of resources
  •  DELETE to delete a resource

To view the detailed Mailtrap API documentation, use this link (it is available in the API section of the main menu as well).

What you can test with the Mailtrap API

Via API, you can run the following commands: 

  • Inbox: create a new inbox, reset the inbox credentials and its email address; receive messages, clean one or all messages in the inbox, mark all messages as read; manage users.
  • Project: Create a new project, update, and delete it; manage its users. 
  • Email forwarding: manage forwarding messages to real email addresses (available starting from the Individual plan). 
  • Email content: inspect the email body by getting raw HTML (you can also download it), text, and detailed info about the HTML part, including a list of possible errors; receive message attachments.
  • Bcc and message headers: receive message headers (Bcc is also included in this section, notwithstanding that it is not a regular message header). Bcc testing is available starting from the Team plan. 
  • Deliverability: get a SPAM report and domain blacklisting details.
  • Manage CORS domains.

This way, you can test and verify the following scenarios: 

  • Email sending script works.
  • Email recipients are correct + Bcc testing (on the advanced plans).
  • HTML template doesn’t cause errors.
  • Mail merge/dynamic content is replaced properly.
  • Appropriate files are attached.
  • Important links, such as reset password and account confirmation, work.
  • Your message doesn’t trigger a spam filter and your domain is not blacklisted, etc.

Learn how you can easily test various user scenarios with a ready to use integration of Kakunin (E2E testing framework) + Mailtrap from our case study with The Software House.

How to get started with the Mailtrap API

  1. Go to the API section of the main menu and copy your token. You can also find your token in the user profile.  
  2. Use this token to send authenticated HTTP requests in one of the following ways:
  • Send an HTTP header Api-Token: {api_token}, where {api_token} is your API token
  • Send a parameter api_token={api_token}, where {api_token} is your API token
  • Send an HTTP header Authorization: Token token={api_token}, where {api_token} is your API token (more info: Token Access Authentication)
  • Send an HTTP header Authorization: Bearer {jwt_token}, where {jwt_token} is your JWT token (more info: JSON Web Token (JWT))

Go to the API documentation, check samples, and experiment in the console.

Still need help? Contact Us Contact Us