Testing 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 Testing API works

The testing API uses REST protocol and can return calls as JSON objects. And it's compatible with the majority of 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 Testing API documentation, use this link. You can also find it in the account drop-down menu in the upper right corner.

What you can test with the Mailtrap Testing 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.

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 Mailtrap Testing API

First, you need to get a token. You can find it under Settings, API Tokens.

To learn more about managing your tokens, please check this guide
Then, there are a couple ways to send authenticated HTTP requests:
  • Send a HTTP header  Api-Token: {api_token}, where {api_token} is your API token
  • Send a HTTP header Authorization: Bearer #{token}, where {api_token}  is your API token (more info: Token Access Authentication)

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

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us