Videos
Check out our tutorial video series.
Use disposable email accounts in Ready API functional tests to receive email confirmation codes
ReadyAPI is a powerful tool for quality assurance and functional testing. This guide demonstrates how to utilize MailSlurp's disposable email APIs in your Ready API tests to generate disposable mailboxes and receive email OTP verification codes for user sign up and confirmation.
Check out the full ReadyAPI example project on GitHub.
Say we are writing functional e2e tests of an application or API using ReadyAPI. We have an endpoint for user sign-up that expects an email address. This email must be unique and once submitted will receive an OTP verification code. Testing this process manually works but is slow and complex: we want to automate it using disposable and unique inboxes that can receive the MFA code. We then need a function to extract the confirmation code from the received email and submit it to confirm the user.
We can use the MailSlurp API definitions and import them into our ReadyAPI studio. These endpoints allow use to create email accounts on demand, receive emails, extract codes, and store those values in our test properties for further steps. All we need is a free API Key set as our Authorization JWT Bearer token.
Our end result will look something like this:

Let's go over how to use email and SMS in ReadyAPI with example. In this test we will use MailSlurp's disposable inbox endpoints to create test email accounts and use them for testing a demo applications email sign-up and verification process.
Authentication should be defined like so:

The screenshot below shows the end test we will be creating.

The steps are the following:
Endpoint: mailSlurpApi
Creates a fresh MailSlurp inbox to receive the verification/OTP email for the test run.
Extract the generated inbox's emailAddress from the response and save it as a TestCase property, so later steps can reuse it.
Endpoint: demoApplication
Triggers the application's sign-up flow using the stored inbox email and a test password.
Endpoint: mailSlurpApi
Polls MailSlurp until the verification email arrives. This waits for the latest email in the created inbox.
Extract the received email's id and store it for use when retrieving or parsing the email content.
Endpoint: mailSlurpApi
Fetches the email content and applies a regex pattern to extract the OTP or verification code from the message body.
Save the extracted OTP code as a TestCase property to be used in the confirmation step.
Endpoint: demoApplication
Send the OTP code back to the application to complete the sign-up and confirm the user.
Once we have added the aMailSlurp API to ReadyAPI as an API integration we can search through the available methods and select those that are needed for our test.

During the test we need to pluck values from the MailSlurp API responses and store them in variables for use later in the test. This image shows how:

To get started yourself, download the test project from GitHub and import it into ReadyAPI studio. For more information see the API Spec and developer docs.
Check out our tutorial video series.
Email and SMS guides for automation and testing.
View github project code for multiple languages.
Latest posts from the MailSlurp team.
Test, build, and automate messaging with a free MailSlurp account.
