Automated Email Testing in 5 Minutes! Send and receive emails in CI and code.

Image for post
Image for post
Email APIs let you create email addresses on demand during automated tests.




npm install --save mailslurp-client
const MailSlurp = require("mailslurp-client").default;
import { MailSlurp } from "mailslurp-client";
const mailSlurp = new MailSlurp({ apiKey: "your_key_here" });

Common use cases

Creating inboxes

const inbox = await mailslurp.createInbox();
"id": "123",
"emailAddress": ""

Sending emails

await mailslurp.sendEmail(inboxId, { to: [""], body: "Hello" });

Receiving emails

waitForLatestEmail(inboxId?: string, timeout?: number): Promise<Email>
test('app sends welcome`, async () => {

const inbox = await mailslurp.createInbox();

await myApp.sendWelcome(inbox.emailAddress);

const welcome = await mailslurp.waitForLatestEmail(


Extracting email content

const email = await mailslurp.waitForLatestEmail(;
// fetch an email
const email = await mailslurp.waitForLatestEmail(;

// execute a regular express capture group on the body and
// destructure the matching group into a variable
const [_, verificationCode] = /your code is "([0-9]{6})"/g.exec(email.body);

// do something with code like verifying an account

Special characters

// notice that "=" is replaced with "&#x3D;" HTML entity
const [_, code] = /\?code&#x3D;([^'"]+)/g.exec(body);

Test Framework integrations


"defaultCommandTimeout": 30000,
"requestTimeout": 30000
const { MailSlurp } = require("mailslurp-client");

Cypress.Commands.add("createInbox", () => {
return mailslurp.createInbox();
it("can sign up", () => {
cy.createInbox((inbox) => {
// etc

Next steps

Test Email API for end-to-end with real email addresses. Support for NodeJS, PHP, Python, Ruby, Java, C# and more. See for details.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store