Here is an actual end-to-end test that we run against our own site's login process. The aim is to sign up a user — which requires the user to receive a verification code via email. This code must then be entered on the account verification page. Without MailSlurp this would be difficult to test.

Our test uses the MailSlurp REST API to:

  • Create a random inbox with an id and email address.
  • Use these details to sign up as a new user.
  • Check the emails in the inbox for a verification code.
  • Extract the code and use it to verify a user.

It is written in Javascript using the Cypress test framework and the official MailSlurp API client.

 * A real test of the MailSlurp sign up process
 * as a demonstration of why and how you would use
 * the MailSlurp API. It's a JS file that is run by
 * Cypress, but the MailSlurp API client used works
 * anywhere. The client is asynchronous and uses promises.

// import an apiKey (which you can find in your dashboard)
// and the official js client (available on npm)
const apiKey = require("./config.json").apiKey;
const MailSlurpClient = require("mailslurp-client");

// instantiate a client for the inbox endpoints
const api = new MailSlurpClient.InboxcontrollerApi();

// test the authentication flow on mailslurp.com
// using Cypress test runenr
describe(`The real MailSlurp.com user 
          signup process, which sends a verification
          code via email that the user must then enter`, () => {
  // placeholders we will set these later using MailSlurp
  let username;
  let emailAddress;

  const password = "test-password";

    `each test, create a new, random email
     inbox and use the address and id to 
     sign-up on Mailslurp.com`,
    done => {
      // create a new email inbox that returns an id and an address
          data => data.payload,
          err => {
            // log or inspect an error here if necessary
            throw err;
        .then(({ id, address }) => {
          username = id;
          emailAddress = address;

  it(`allows signup with a generated inbox 
      and username that we got from MailSlurp`, () => {
    // use the username and email address we got
    // from MailSlurp to sign a user up by filling out
    // the sign-up form

  it(`Mailslurp.com then sends an email to the new user's
      email address (using some transactional email service).
      In our test we'll use the MailSlurp API to wait for and return
      the email, from which we can read the verification code
      and enter it into the verification form`, () => {
    let verificationCode;
    cy.location("pathname").should("eq", `/verify/${username}`);
    // use cypress's async api
    cy.then(() => {
      // check the users inbox and hold the
      // connection until one email is present
      return api
        .getEmailsForInboxUsingGET(apiKey, username, {
          minCount: 1,
          maxWait: 90
          data => data.payload,
          err => {
            throw err;
        .then(([latestEmail]) => {
          // regex match for the confirmation code
          // within the email body
          const r = /\s(\d{6})\./g;
          // extract the verication code
          verificationCode = r.exec(latestEmail.body)[1];
    // submit the code we extracted from the email
    cy.get("#code").then(input => {

  it(`successfully verifies the user 
      and allows the user to login`, () => {
    cy.location("pathname").should("eq", "/login");
    cy.location("pathname").should("eq", "/dashboard");

If you want to run this test you can use this config file.