{"id":15552193,"url":"https://github.com/bahmutov/cypress-ethereal-email-example","last_synced_at":"2025-09-28T20:30:58.515Z","repository":{"id":37661053,"uuid":"365257760","full_name":"bahmutov/cypress-ethereal-email-example","owner":"bahmutov","description":"Using an external Ethereal email inbox during Cypress tests","archived":false,"fork":false,"pushed_at":"2024-10-23T07:50:29.000Z","size":2341,"stargazers_count":21,"open_issues_count":7,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-24T18:50:45.597Z","etag":null,"topics":["cypress-email-testing-example","cypress-example"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-05-07T14:21:00.000Z","updated_at":"2024-05-30T02:21:12.000Z","dependencies_parsed_at":"2024-03-09T07:28:09.902Z","dependency_job_id":"965377e5-920b-4ef9-876a-a44c509f1763","html_url":"https://github.com/bahmutov/cypress-ethereal-email-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-ethereal-email-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-ethereal-email-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-ethereal-email-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Fcypress-ethereal-email-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/cypress-ethereal-email-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234558803,"owners_count":18852283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cypress-email-testing-example","cypress-example"],"created_at":"2024-10-02T14:11:44.969Z","updated_at":"2025-09-28T20:30:57.812Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-ethereal-email-example\n\n[![ci status][ci image]][ci url] [![badges status][badges image]][badges url] [![renovate-app badge][renovate-badge]][renovate-app] ![cypress version](https://img.shields.io/badge/cypress-9.7.0-brightgreen) [![cypress-ethereal-email-example](https://img.shields.io/endpoint?url=https://dashboard.cypress.io/badge/simple/v1m866/main\u0026style=flat\u0026logo=cypress)](https://dashboard.cypress.io/projects/v1m866/runs)\n\n\u003e Using an external [Ethereal email](https://ethereal.email/) inbox and [Sendgrid](https://sendgrid.com/) to test emails\n\nRead the blog post [\"Full Testing of HTML Emails using SendGrid and Ethereal Accounts\"](https://www.cypress.io/blog/2021/05/24/full-testing-of-html-emails-using-ethereal-accounts/)\n\n![HTML Email](./images/confirm.png)\n\n**Note:** if you are using an SMTP server directly to send emails, take a look at [cypress-email-example](https://github.com/bahmutov/cypress-email-example) repository where we spawn our own SMTP server right from the Cypress during tests.\n\n## Install and run\n\nThis application uses Sendgrid to send emails, thus you need to configure an account and expose it via environment variables\n\n```\nSENDGRID_HOST=smtp.sendgrid.net\nSENDGRID_PORT=465\nSENDGRID_USER=\nSENDGRID_PASSWORD=\n# the same as verified sender\nSENDGRID_FROM=\n```\n\n**Tip:** use [as-a](https://github.com/bahmutov/as-a) utility to inject a block of environment variables when running a command.\n\nThe above variables are only needed for the `npm start` process, as Cypress creates its own temporary email [Ethereal email inbox](https://ethereal.email/).\n\n```shell\n$ npm install\n$ npm start\n# from another terminal\n$ npx cypress open\n# click the spec.js\n```\n\n## Application\n\nNext JS application showing the confirm page, emailing a confirmation code and storing it in the database. The API hook [pages/api/register.js](./pages/api/register.js) uses [src/emailer.js](./src/emailer.js) to send the email using the SMTP config from the environment variables.\n\nOnce the user gets the email, they enter the confirmation code that is checked against the database by [pages/api/confirm.js](./pages/api/confirm.js).\n\n## The test\n\nThe temporary email account is created by [cypress/plugins/email-account.js](./cypress/plugins/email-account.js) code called from the [cypress/plugins/index.js](./cypress/plugins/index.js). The [cypress/integration/spec.js](./cypress/integration/spec.js) does the full end-to-end test:\n\n- opens the application page\n- enters the temporary email address\n- checks the temporary email address to get the last email\n- loads the HTML email in the Test Runner\n- grabs the confirmation code and clicks the confirm button\n- enters the extracted confirmation code\n- verifies the page shows \"Success\"\n\nThe start of the test\n\n![The start of the test](./images/test-start.png)\n\nThe second part of the test\n\n![The end of the test](./images/test-end.png)\n\n## Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2021\n\n- [@bahmutov](https://twitter.com/bahmutov)\n- [glebbahmutov.com](https://glebbahmutov.com)\n- [blog](https://glebbahmutov.com/blog)\n- [videos](https://www.youtube.com/glebbahmutov)\n- [presentations](https://slides.com/bahmutov)\n- [cypress.tips](https://cypress.tips)\n- [Cypress Advent 2021](https://cypresstips.substack.com/)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/cypress-ethereal-email-example/issues) on Github\n\n## MIT License\n\nCopyright (c) 2021 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[ci image]: https://github.com/bahmutov/cypress-ethereal-email-example/workflows/ci/badge.svg?branch=main\n[ci url]: https://github.com/bahmutov/cypress-ethereal-email-example/actions\n[badges image]: https://github.com/bahmutov/cypress-ethereal-email-example/workflows/badges/badge.svg?branch=main\n[badges url]: https://github.com/bahmutov/cypress-ethereal-email-example/actions\n[renovate-badge]: https://img.shields.io/badge/renovate-app-blue.svg\n[renovate-app]: https://renovateapp.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-ethereal-email-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Fcypress-ethereal-email-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Fcypress-ethereal-email-example/lists"}