How to define an additional mailer service to use the spool and send instant emails in Symfony2
I found the solution here
This is how I implemented it:
First, I configured the default mailer service to work as a spool to send 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 bundles (CommonBundle) I registered a new service called "instant_mailer" that maps to 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 usning the spool I just do:
$mailer = $this->get('mailer');
And to send an instant email:
$mailer = $this->get('instant_mailer');