Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I acess content of email triggered by a test in Cypress

An email is being sent in my case ( 1. When resetting the password, 2. Adding a New member) during both API and UI tests. How can I access these emails without actually logging into my mail manual and accessing the content, so I can add them to the test and verify?

The test is something like the below.

  1. User can reset the password.
  2. Mail is triggered.
  3. User uses the link in the mail to reset the password.
  4. User logs in again using the new password.

Second test.

  1. Admin adds a member.
  2. Admin adds a new member and gets a mail about confirmation.
  3. verify the mail sent to the new member's email.

Would appreciate any help here.

I have tried to look into the third parties but it seems I need to use their email accounts I was hoping if someone can help me regarding Gmail(accessing the content of emails going to Gmail)

like image 843
ruffainn Avatar asked Jan 19 '26 18:01

ruffainn


2 Answers

  1. If your application is running locally and is sending the emails directly through an SMTP server, you can use a temporary local test SMTP server running inside Cypress. Read the blog post "Testing HTML Emails using Cypress" for details.
  2. If your application is using a 3rd party email service, or you cannot stub the SMTP requests, you can use a test email inbox with an API access. Read the blog post "Full Testing of HTML Emails using SendGrid and Ethereal Accounts" for details.

Taken from the official best practice page at "Verifying sent emails". Read more here.

like image 118
Martin van Driel Avatar answered Jan 21 '26 06:01

Martin van Driel


There are various 3rd party solutions that provide real email addresses you can access via an API. These come with plugins for Cypress that can help you with exactly this scenario. See here: https://docs.cypress.io/plugins#email

Some also offer SMTP servers which is useful in staging or dev environments so all email gets captured in them and you don't send external emails.

Our company uses Mailosaur to test both of the scenarios you mention, password reset and email validation during account creation but of course you can use others mentioned here too.

like image 28
anichols Avatar answered Jan 21 '26 07:01

anichols



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!