I found a solution here
Here's how I implemented it:
First, I set up the default mail service to act as a coil for sending bulk emails.
(config.yml)
swiftmailer: transport: %mailer_transport% encryption: %mailer_encryption% auth_mode: %mailer_auth_mode% host: %mailer_host% username: %mailer_user% password: %mailer_password% spool: type: file path: "%kernel.root_dir%/spool"
Then, inside one of my packages (CommonBundle), I registered a new service called "instant_mailer", which appears in the Swiftmailer class.
(service.yml)
instant_mailer: class: %swiftmailer.class% arguments: ["@?swiftmailer.transport.real"]
Finally, in my controller, whenever I want to send an email using a coil, I just do:
$mailer = $this->get('mailer');
And send an instant email:
$mailer = $this->get('instant_mailer');
source share