2.1 KiB
2.1 KiB
Email Delivery: Dev Mailcatcher & Production Mailgun
This application uses Symfony Mailer. We separate development and production delivery:
- Development: Mailpit (mailcatcher) via SMTP in Docker.
- Production: Mailgun via API transport.
Development (Mailpit)
- Service is defined in
compose.override.yamlasmailer(axllent/mailpit). - Ports:
- SMTP: 1025 (mapped to host 1025)
- Web UI: 8025 (mapped to host 8025)
- Default DSN for dev is set in
.env:
MAILER_DSN=smtp://mailer:1025
- Usage:
- Start stack:
docker-compose up -d - Send an email from the app.
- Open http://localhost:8025 to view captured emails.
- Start stack:
Production (Mailgun)
Use the Mailgun API transport (symfony/mailgun-mailer bridge). Do not commit secrets.
- Example configuration is in
.env.prod:
MAILER_DSN=mailgun+api://${MAILGUN_API_KEY}:${MAILGUN_DOMAIN}@default?region=eu
region=euis only needed if the Mailgun account/domain was created in Mailgun's EU region (common for.nl/EU-based senders). Drop it (or useregion=us) if the domain lives in the US region.- Provide
MAILGUN_API_KEYandMAILGUN_DOMAINvia:- Real environment variables on the server/container, or
- Symfony secrets:
php bin/console secrets:set MAILGUN_API_KEY(and dump for prod), or - Orchestration secret stores (e.g., Docker/K8s).
- The sending domain must be added and DNS-verified (SPF/DKIM/tracking CNAME) in the Mailgun dashboard before production sending will work reliably; unverified domains are rate-limited/sandboxed.
Notes
- No Mailpit container is defined in the base
compose.yaml, only incompose.override.yaml. This ensures it is used in development only. - To test email locally without Docker, you can:
- Run Mailpit on your host (ports 1025/8025) and set
MAILER_DSN=smtp://127.0.0.1:1025in.env.local.
- Run Mailpit on your host (ports 1025/8025) and set
- If you need to use Mailgun SMTP instead of API, a DSN example:
mailgun+smtp://USERNAME:PASSWORD@default?region=eu(username/password come from the Mailgun domain's SMTP credentials). - Use
php bin/console app:mail:test you@example.comto send a quick test email against whateverMAILER_DSNis currently configured.