Communication
Transactional email system with Brevo and Mailpit
Communication
What's Included
- Three transactional email templates (welcome, password reset, password changed)
- Brevo integration for production emails
- Mailpit for local development (catches all outgoing emails)
- Environment-based adapter swap — no code changes between dev and prod
Email Architecture
Two adapters implement EmailSenderInterface:
| Environment | Adapter | Delivery |
|---|---|---|
| Production | BrevoTransactionalEmailSender | Brevo API with template IDs |
| Development | SymfonyMailerEmailSender | Symfony Mailer → Mailpit |
Both adapters implement the same domain port, keeping the application layer decoupled from the delivery mechanism. The swap is configured in config/services.yaml via environment-specific overrides:
# config/services.yaml
App\UserManagement\Domain\Port\EmailSenderInterface:
'@App\UserManagement\Infrastructure\Email\BrevoTransactionalEmailSender'
when@dev:
services:
App\UserManagement\Domain\Port\EmailSenderInterface:
'@App\UserManagement\Infrastructure\Email\SymfonyMailerEmailSender'
Transactional Emails
| Trigger | Template Variables | |
|---|---|---|
| Welcome | User registration | userName, link (validation) |
| Password Reset | Forgot password request | userName, link (reset) |
| Password Changed | Password change or reset | userName |
All emails are sent asynchronously via domain events. If sending fails, the error is logged but does not block the originating action.
Brevo Setup (Production)
1. Create Templates
Create 3 transactional email templates in your Brevo dashboard using the template variables listed above.
2. Configure Template IDs and Environment Variables
See Configuration > Brevo Email Templates for template ID mapping and required environment variables.
Mailpit (Local Development)
In development, all emails are caught by Mailpit instead of being sent to real addresses. The Mailpit web UI is available at:
All emails sent during development appear here, making it easy to test email flows without configuring a real email provider.