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:

EnvironmentAdapterDelivery
ProductionBrevoTransactionalEmailSenderBrevo API with template IDs
DevelopmentSymfonyMailerEmailSenderSymfony 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

EmailTriggerTemplate Variables
WelcomeUser registrationuserName, link (validation)
Password ResetForgot password requestuserName, link (reset)
Password ChangedPassword change or resetuserName

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:

http://localhost:8025

All emails sent during development appear here, making it easy to test email flows without configuring a real email provider.