Videos
Check out our tutorial video series.
Send and receive email using isolated test email accounts within JMeter stress tests
JMeter is a powerful load testing framework from Apache that lets you run large scale stress tests against networks and APIs. Sometimes these systems rely on email messaging, for instance user sign-up, bulk marketing, email blasts, and notification systems. When email is required we can use disposable test email accounts from MailSlurp to send and receive email during JMeter tests.
Say we have a sign-up process in our application that accepts a user email address and then sends a confirmation code. What happens when our system is under heavy load, say during a live event or promotion? Well to test this we can use JMeter. We define steps using either a GUI, XML, or Java. These steps should do the following:
If you don't have JMeter already download it and place in your project root. Unzip the files and execute the GUI using:
This should show a user interface like so:
To create email accounts during JMeter load tests use the free MailSlurp API. The key endpoints are:
Request | Description |
---|---|
POST https://api.mailslurp.com/inboxes | Creates a new disposable inbox and returns its id + emailAddress. |
GET https://api.mailslurp.com/waitForLatestEmail?inboxId={INBOX_ID}&timeout=60000&unreadOnly=true | Polls MailSlurp until the latest unread email arrives in that inbox. |
Note: for each request we must append a MailSlurp API KEY as an header:
Let's go over the steps now needed to write the load test for our application sign up process.
To generate a new dummy mailbox make a request to
with your API KEY set to the
header. This returns an ID and emailAddress we can store for the next steps:
Make sure we set the headers to pass a valid MailSlurp API KEY (Get a free key here).
Next we need to store the returned JSON result so we can sign up with the email address and then read the emails:
Now that we have an email in our load test, use it to sign up and stress test our application. Here we will test a dummy app:
If our system is working correctly it will send an email to that email address that we can wait for using MailSlurp.
Lastly, we can now use the inbox ID stored earlier to receive the sent email and verify our system is operational during load tests. For this we call and pass a
milliseconds and
parameter. This will hold the connection open until our expected email arrives in the inbox. This makes waiting for emails easier without any additional retry logic.
Then test the email is present:
Here is a full example you can save and load into JMeter:
You can run this test in the command line like this:
Another way to write JMeter tests is with JUnit and maven. Here we can use the MailSlurp Java Library to create an inbox and receive the confirmation email after user sign up.
See the full examples on Github and go to MailSlurp to create a free account and start testing.
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.