Skip to main content

Cypress Mailosaur Plugin

Cypress has a plugin called mailosaur, which helps do all the end-to-end testing stuff needed on the email area like resetting the password, reading subject, account verification, you name it.

This article will see how we can set up mailosaur in our cypress environment and get started.

In our cypress environment, type in the following and install mailosaur.

npm install cypress-mailosaur --save-dev

This will install mailosaur special cypress commands.

Go to command.js in the support folder and type in the following.

import 'cypress-mailosaur'

This will let cypress know about mailosaur.

Then go to index.js in the same folder and type in the following.

  • This is a crucial step, or else we get a function not recognized error when mailosaur functions are used.
  • For example, we will do tests on the mailosaur server, which is free for a limited time. Sign up and get started.

  • Here we have already created a test server to start working on it.

  • Create an API key by clicking on 'create a key' and copy it.
  • Go to cypress.json and type in the following.
    "env": {
        "MAILOSAUR_API_KEY": "frbPNNiS0NL5xaYD"

  • This will provide the API key for the mailosaur for cypress testing.

Now let us reset the mail password using mailosaur and mailosaur test server as mail site.

describe('Mailosaur Demo',() => {
    const serverId = "rdgw9gfd"
    const serverDomain = ""
    const email = 'mailo@' +serverDomain

    let resetLink
    it('Should send reset mail',()=>{
        cy.mailosaurGetMessage(serverId, {
            sentTo: email
        }).then(emaill => {
            resetLink = emaill.html.links[0].href
    it('Should reset password',()=>{


  • So we can see that the serverid and domain from mailosaur have been stored in a variable separately.
  • We can have anything before the '@' for email id, followed by the serverdomain, which will work and send messages.
  • Next, we have declared a static variable resetLink.
  • In the first test step, we visit the site where we need to reset the password.
  • The email has been typed and submitted.
  • Once that is done, an email is sent to our mailosaur test server.
  • We can confirm it by using the cy.mailosaurGetMessage function and logging it.
  • The link within its body has been stored inside the static variable we declared.
  • In the following test step, we visit the reset link we extracted using the then command, which yielded the mailosaurGetMessage result.
  • We navigate to that link and reset the password successfully when we do that.

So this is how mailosaur works, and this is just one way of showing its true power.

Submitted by arilio666 on April 27, 2022

Ashwin is working with iVagus as a Technical Lead. He has experience in various technologies like Cypress, JavaScript, TypeScript, Rest Assured, Selenium, Cucumber, and Java.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.