Mailhog - Email Testing ¶
Based on: https://medium.com/kreuzwerker-gmbh/e2e-testing-of-emails-in-mailhog-using-cypress-72ccb722bad7
Laravel ¶
Update the following files:
docker-compose.local.yml
Under “services” add:
mailhog:
image: mailhog/mailhog:latest
ports:
- '8025:8025'
- '1025:1025'
environment:
MH_STORAGE: maildir
MH_MAILDIR_PATH: /tmp
volumes:
- maildir:/tmp
command: -invite-jim=1 -jim-accept=0.50
networks:
- indevets_local_net
And under “volumes” add:
maildir: {}
envs/env.local
Update the Mailtrap secttings:
MAIL_HOST=mailhog
MAIL_PORT=1025
# MAIL_USERNAME=affffceaa5d321
# MAIL_PASSWORD=d9d17a0d48a800
MAIL_ENCRYPTION=
Note: There are differences here between Laravel versions. This StackOverflow helped to find the fix: https://stackoverflow.com/questions/65420438/laravel-5-2-expected-response-code-220-but-got-code-500-with-message-500-un
Laravel 8 works with…
MAIL_ENCRYPTION=null
…but Laravel 6 needed…
MAIL_ENCRYPTION=
Cypress + Mailhog ¶
Install Cypress-Mailhog package
yarn add --dev cypress-mailhog
cypress/support/commands.js
Add
import 'cypress-mailhog';
cypress.json
Add:
"mailHogUrl": "http://localhost:8025"
Mailhog browser GUI ¶
http://localhost:8025