Set up docker-compose to use MailDev with symfony-based project
Testing emailing during development is always tedious and risky. Especially when using Docker.
Therefore it is recommended to use a mail catcher and sender like MailCatcher or MailDev.
MailDev is both a light SMTP server and a catcher for all emails send through it. It also enable relay of selected email to another SMTP server to check email rendering ‘in real world’
Here is how to configure our docker-compose file to use MailDev out of the Docker box with symfony project in 3 easy steps:
Given you already have a docker-compose.yml file with your dockerised symfony app.
1/ Add MailDev container to your docker-compose:
Mail server is on port 1025, and webmail MailDev client is on port 1080
2/ Modify symfony .env file
With SymfonyMailer add/modify:
MAILER_DSN=smtp://maildev:1025
With Swiftmail add/modify:
MAILER_URL=smtp://maildev:1025
RQ: replace ‘maildev’ with the name given to maildev container in your docker-compose file
3/ Check sent mails
Connect to http://localhost:1080 and enjoy :)
BONUS:
If you have a smtp relay server, you could configure MailDev to send catch emails to external mailboxes by adding this command: