User Bundle Mailer

The User Bundle can send user lifecycle emails, but the mailer integration is disabled by default.

Enable it only when the application sends emails from the bundle, such as:

  • register confirmation emails
  • reset password emails
  • invitation emails
  • resend confirmation emails from user settings or the admin area

Projects that only use external authentication, for example Google Identity Platform, can keep the mailer disabled.

Requirements

Install Symfony Mailer before enabling the bundle mailer:

composer require symfony/mailer

Then enable the feature:

YAML

sfs_user:
    mailer:
        enabled: true

PHP

<?php

// config/packages/sfs_user.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
    $container->extension('sfs_user', ['mailer' => ['enabled' => true]]);
};

The bundle fails during configuration when sfs_user.mailer.enabled is true but symfony/mailer is not installed.

Keep the mailer disabled when the application does not send user emails:

YAML

sfs_user:
    mailer:
        enabled: false

PHP

<?php

// config/packages/sfs_user.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
    $container->extension('sfs_user', ['mailer' => ['enabled' => false]]);
};

What The Mailer Sends

When enabled, the bundle registers UserMailerInterface and the automatic email listeners.

The default mailer sends:

  • ConfirmationEmail after registration when the user implements ConfirmableInterface
  • ResetPasswordEmail after a valid reset password request when the user implements PasswordRequestInterface
  • InvitationEmail when an invitation is created and the invitation feature is enabled

The admin and settings resend actions also use the same mailer when it is available. Delivery failures are logged and do not necessarily roll back successful user or invitation creation. Check the logs and test the resend path when verifying onboarding.

For local verification, use a mail catcher or Symfony's null://null transport rather than a real recipient. Verify generated message content separately from delivery.

Configure Sender Data

The mailer configuration accepts a sender address and name:

YAML

sfs_user:
    mailer:
        enabled: true
        from:
            address: 'no-reply@example.com'
            name: 'Example'

PHP

<?php

// config/packages/sfs_user.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
    $container->extension('sfs_user', [
        'mailer' => ['enabled' => true, 'from' => ['address' => 'no-reply@example.com', 'name' => 'Example']],
    ]);
};

Use project configuration or environment variables for real deployments.

Mail Template Integration

If softspring/mailer-bundle is installed, the User Bundle registers its mail templates through MailTemplateLoader.

The provided template ids are:

  • sfs_user.reset_password
  • sfs_user.register_confirm
  • sfs_user.invite

Use this integration when the project manages email content through the Mailer Bundle.

If softspring/mailer-bundle is not installed, the User Bundle can still send the default Symfony Mailer messages when symfony/mailer is installed and sfs_user.mailer.enabled is true.

Replace The Mailer

Replace or decorate Softspring\UserBundle\Mailer\UserMailerInterface when the project needs a different email generation or delivery strategy.

Example:

YAML

services:
    App\User\UserMailer:
        decorates: Softspring\UserBundle\Mailer\UserMailerInterface

PHP

<?php

// config/services.php
namespace Symfony\Component\DependencyInjection\Loader\Configurator;

return static function (ContainerConfigurator $container): void {
    $services = $container->services();

    $services->set(\App\User\UserMailer::class)
        ->decorate(\Softspring\UserBundle\Mailer\UserMailerInterface::class);
};

Prefer decorating the service when you only need to add behaviour before or after sending.

Replace it completely when the email content, template engine, or delivery channel must be different.