How to define an additional email service to use spool and instant messaging in Symfony2

In my Symfony2 web application, I have to send two types of emails: instant and bulk. Instant emails should be sent immediately, and bulk emails should be sent using a coil. With the default Swiftmailer setting in Symfony2, this cannot be done because there is only one mail service.

Similar questions are asked here in SO ( How to copy emails (to a task) and send regular emails at the same time to other controllers? ) Without luck, but in accordance with this github stream ( https://github.com/symfony/ SwiftmailerBundle / issues / 6 ) you can create a second mail service that can be fully configured, by default one. Someone out there (stof) recommended, as a possible solution, to perform the configuration found in the SwiftmailerBundle ( https://github.com/symfony/SwiftmailerBundle/blob/master/Resources/config/swiftmailer.xml ) to create this new service, but I don’t know how to do it.

Does anyone know how to create an additional mail service that I can configure as a coil, having a default mail service for sending regular (instant) emails?

+6
source share
1 answer

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'); 
+11
source

Source: https://habr.com/ru/post/924585/


All Articles