Postman is a powerful tool for testing APIs. In this guide we will show you how to use Postman to test email sign-up APIs. We will use the MailSlurp API to create inboxes inside tests and use them to receive MFA codes during sign-up for a dummy application.

Run In Postman

About

Many applications use email and password signup and login authentication. Often these applications require email verification or multi-factor authentication (MFA) to secure user accounts. With the MailSlurp API we can use Postman to create disposable email accounts during testing of sign-up APIs that require email verification or MFA. It this example we will show you how to create a Postman collection that:

  • Creates a new inbox for each test
  • Sends a sign-up request to a dummy API
  • Waits for an email to arrive in the inbox
  • Extracts the MFA code from the email
  • Sends the MFA code to the API to complete sign-up

A copy of this collection is hosted on Postman.

Why do we do this?

We want to know that our dummy server application allows user sign up and functions correctly. This is a critical aspect of any application so it is good to be confident it works as expected. The dummy app sends a verification code via email that must be submitted by the user to confirm the address. We will use MailSlurp's free throwaway email accounts to receive the verification code and submit it back to the server.

Steps

Make sure you have a free MailSlurp API KEY and pass it as a header .

Create an email address

First step in our test is to create a new email address using the MailSlurp API.

Use a post request script to store the and as collection variables.

Sign up new user

Next we will send a sign-up request to our dummy server application. This will cause the server to send a verification email to the email address we created in the previous step.

Wait for email

Now we can call the MailSlurp waitFor API to hold a test open until an email arrives in the inbox we created. This is useful for testing asynchronous email sending.

In the post request scripts we can save the for the matching email as a collection variable.

Extract confirmation code

We can use the MailSlurp contentMatch API to extract the confirmation code from the email body using a regex pattern.

Using the regex pattern we can extract the confirmation code from the email body and save it as a collection variable for use in the next step.

Submit confirmation code

Now we can send the confirmation code back to the server to complete the sign-up process.

A 2xx response code indicates that the sign-up process was successful.

Login with confirmed account

Lastly we can test that the user can login with the confirmed account.

Conclusion

The examples above show how to use Postman to test email sign-up APIs using MailSlurp. By creating inboxes inside tests we can send and receive emails during API collection test runs. This is useful for testing email verification and MFA processes in applications that require email sign-up.

For more information, see our developers documentation and Postman examples.