Skip to main content

Selenium email and SMS plugin

Use email and SMS in Selenium tests using MailSlurp. Integrate easily with existing Selenium projects. Simple add the NodeJS, Java, CSharp or Python MailSlurp package to your test environment then you can create email addresses, send and receive emails, and send and receive TXT messages.


Loading examples...




Install the MailSlurp package for your language and then configure it with your API Key. See the SDKs page for more information.


Add the maven central package.



Use the Nuget package:

dotnet add package mailslurp


Add the NPM package.

npm install --save mailslurp-client


Use the PyPi package.

pip install mailslurp-client


Once you have installed the MailSlurp package you can use it to create email addresses, send and receive emails, and send and receive SMS messages in your Selenium tests.

The following sections will give usage examples in Java and Typescript but you can use the same methods in any language.

Creating inboxes

You can create inboxes that are disposable or permanent. Use name, description, or tags to so you can find it again.

// use names, description, and tags to identify an inbox
String randomString = String.valueOf(new Random().nextLong());
String customName = "Test inbox " + randomString;
String customDescription = "My custom description " + randomString;
String customTag = "test-inbox-" + randomString;
// create inbox with options so we can find it later
CreateInboxDto options = new CreateInboxDto()
InboxDto inbox = inboxControllerApi.createInboxWithOptions(options);

Finding inboxes

You can either create a new inbox each test run or fetch an existing inbox. When fetching you can either get it directly by the ID or search for it. When searching you need something to search for such as an email address of the name, description, or tags used when the inbox was created.

Get inbox by address or name

Get an inbox by name or address like so:

// get inbox by id
InboxDto inboxById = inboxControllerApi.getInbox(inbox.getId());

// lookup inbox by address
InboxByEmailAddressResult inboxByAddress = inboxControllerApi.getInboxByEmailAddress(inbox.getEmailAddress());
assertEquals(inboxByAddress.getInboxId(), inbox.getId());

// lookup inbox by name
InboxByNameResult inboxByName = inboxControllerApi.getInboxByName("Non-existing inbox");

Search for an inbox

Use search methods to search for an inbox:

PageInboxProjection inboxSearchResult = inboxControllerApi.searchInboxes(
new SearchInboxesOptions()
assertEquals(inboxSearchResult.getNumberOfElements(), Integer.valueOf(1));
assertEquals(inboxSearchResult.getContent().get(0).getId(), inbox.getId());

Waiting for messages

MailSlurp wait for methods allow you to wait for an expected email or SMS to arrive during testing.

WaitForControllerApi waitForControllerApi = new WaitForControllerApi(mailslurpClient);
List<EmailPreview> matchingEmails = waitForControllerApi.waitFor(new WaitForConditions()
.addMatchesItem(new MatchOption()
.value("Test subject")


Searching for messages

You can search for messages too.

EmailControllerApi emailController = new EmailControllerApi(mailslurpClient);
PageEmailProjection emailSearch = emailController.searchEmails(
new SearchEmailsOptions()
.searchFilter("Test subject")

Note: searching will not wait for matching conditions. Use the waitFor methods to ensure matches await expected emails in case they have not yet arrived.

Getting content

You can get the content of emails and SMS messages.

Email email = emailController.getEmail(emailId, false);
assertEquals(email.getSubject(), mySubject);

Extract codes

Use RegExp patterns to extract codes from emails or SMS messages.

// query HTML for content
const { matches: [, captureGroup]} = await emailController.getEmailContentMatch({
emailId: emailId,
contentMatchOptions: {
// use regex capture groups to extract codes
pattern: 'Your verification code is: (\\d{6})',

You can also extract links from messages.

// get links from email content
const { links } = await emailController.getEmailLinks({
emailId: emailId,

Query HTML

You can use XPath or CSS selectors to query HTML content.

// query HTML for content
const { lines } = await emailController.getEmailHTMLQuery({
emailId: emailId,
htmlSelector: '.heading > .username'