If you work with APIs you have probably heard of tools like Insomnia and Postman. These can be used to call and chain API requests when testing and developing software. But did you know you can also use them to create disposable email accounts then send and read emails from within your HTTP workspaces and tests? This article will show you how.

What is Insomnia?

Kong's Insomnia software is a popular open-source desktop tool used primarily for designing, debugging and testing HTTP-based APIs. It's designed to help developers and testers easily create, manage, and execute REST, SOAP, GraphQL, GRPC requests. Its user-friendly interface and advanced features, such as environment management and request chaining, make it perfect for interacting with complex API test suites.

How can I test emails with Insomnia?

Testing email functionality is crucial for applications that rely on email interactions for features like account creation, password resets, and notifications. Email is a different protocol than HTTP so how can the Insomnia API testing tool use it? Well by calling MailSlurp APIs you can proxy SMTP request through HTTP and therefore send and receive email or SMS during your Insomnia tests. This means you can test API endpoints such as user sign up, password reset, verification links, and newsletter sign-up.

Mailslurp

In case you're unfamiliar, MailSlurp is an email and SMS API service that enables developers to create, send, and manage messages in code and no-code dashboards for application testing and development. It's a crucial tool for automating and validating email and SMS functions in software.

How to utilise the MailSlurp API in Insomnia REST Client (Example)

First, create a free MailSlurp account and copy your API KEY from the dashboard. We will use this to create disposable email accounts and send and receive emails from within the software Insomnia.

Download and install Insomnia

If you haven't already create an Insomnia account and download the app. Now open the app.

Import the MailSlurp OpenAPI spec

To aid with your testing import the Swagger/OpenAPI spec for MailSlurp into your Insomnia instance. You can also paste the URL below into the import screen:

Once successful you will see this screen:

After that you can view the MailSlurp API spec and use it to control emails during your QA testing or request chaining:

Setting your authentication

When calling MailSlurp endpoints we need to set the header to use our MailSlurp API_KEY. You can set this in the Auth section of the request builder. Open the auth panel for a new request:

Add your API Key like so:

Now we are ready to create inboxes and control email.

Create an email address in Insomnia tool

To create an inbox we can call the endpoint. The request looks like this:

Or visually:

Note the JSON response:

We can use the returned to control the mailbox in further tests.

Send email with Insomnia HTTP

Next we can use the inbox ID to send an email from the mailbox to a recipient. For the next request we need to enable the JSON body:

Now create a request that matches this structure:

In the app this looks a bit like this:

The response from the method gives us a sent email receipt. We can use this to confirm the details or fetch the sent message:

Excellent! We just sent an email using Insomnia test. Now let's use MailSlurp methods to wait for the email to arrive and read the contents.

Reading email

When we want to read an email we need to wait for it to arrive in the inbox. Luckily MailSlurp handles that for us by holding the connection open until the expected email is received. We can do this with a request like so:

The request should appear something like this in the Insomnia application:

The response from the MailSlurp server shows us the email content:

Voila, you have now created a throwaway email account and used Insomnia testing tool to send and fetch emails using HTTP instead of SMTP. There are many more things you can do with Insomnia and MailSlurp *including controlling text/SMS messages and creating webhook automations) so check out the developer docs for more information.

Why is email important when using Insomnia?

You can utilize email in Insomnia in many ways. Imagine all the endpoints you could test involving email - such as forgot password pages, user sign-up, customer journey emails, support interactions and more.