Skip to content

LeoHernandez-QA/cypress-email-example

 
 

Repository files navigation

cypress-email-example

Sending emails using nodemailer, receive the using smtp-tester or Mailinator and testing the received email using Cypress. The Realmail branch uses Mailinator API to check the inbox and get the confirmation code, while the Dev branch uses a local receiver.

The HTML email test

Before start, create a .env file in the root directory:

You should replace this with real email data and sign up for a Mailinator account to obtain the API token.

MAIL_SENDER_ADDRESS='[email protected]'
MAIL_SENDER_PASSWORD='testpassword'
MAIL_SMTP_HOST='smtp.hostinger.com'
MAIL_SMTP_PORT=465
MAILINATOR_API_URL='https://api.mailinator.com/api/v2/domains/private'
MAILINATOR_API_TOKEN='YourMailinatorTokenHere'
MAIL_RECEIVER_ADDRESS='[email protected]'

Install

$ npm install

Cypress open

$ npm start
# from another terminal:
$ npx cypress open
# click the send-real-email-spec.js

Headless mode

$ npm run test

The application

The application shows the registration page pages/index.js where the user can fill the email and click the submit button. The page makes an Ajax request to the pages/api/register.js handler which sends an email. The email has the confirmation code the user is expected to enter on the confirmation page pages/confirm.js.

Email server

The emails are sent using nodemailer, see emailer.js. During tests the SMTP server is running inside cypress/plugins/index.js process.

About

Testing HTML emails using Cypress.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 56.4%
  • HTML 43.6%