How to define an additional mailer service to use the spool and send instant emails in Symfony2

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-29 04:25:11

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');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!