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.
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]'
$ npm install
$ npm start
# from another terminal:
$ npx cypress open
# click the send-real-email-spec.js
$ npm run test
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.
The emails are sent using nodemailer, see emailer.js. During tests the SMTP server is running inside cypress/plugins/index.js process.