How to configure mailer?

Sylius uses SyliusMailerBundle, which is based on the Symfony Mailer to provide a powerful and customizable email system. This allows you to configure easily:

  • Environment-based mail transports

  • Email localization

  • Named email templates


🔧 Basic Setup

Sylius relies on Symfony's MAILER_DSN system to define the email provider. You’ll usually define this in your .env files.

Example (Using Mailtrap):

MAILER_DSN=smtp://username:[email protected]:2525

✅ Example Configuration per Environment

Production (.env.prod)

In production, just provide a valid DSN.

# env.prod

MAILER_DSN=smtp://apikey:your-api-key@sendgrid

No extra steps are needed unless you want to customize delivery logic (e.g., retry policies, queuing, etc.).


Development & Testing (.env.local / .env.test)

Two common options:

Option A: Disable Email Delivery (Default)

# for example env.local

MAILER_DSN=null://default

Emails won’t be sent — great for running automated tests without side effects.

Option B: Use MailHog (Visual Email Debugger)

# for example env.local

MAILER_DSN=smtp://localhost:1025

Launch MailHog and view emails at http://localhost:8025.

Security Reminder

Last updated

Was this helpful?