Send emails via memory in controllers and spool in some commands in Symfony2

放肆的年华 提交于 2019-12-02 02:38:36

问题


I need to use the spool option to send massive emails to my users, but i won't to change whole config of my app to spool because my register system send an email to the user and i want that this email be instant send.

Is any way to do this without change the global config for swiftmailer?


回答1:


You can configure different emailers. For example:

swiftmailer:
    default_mailer: spool_mailer
    mailers:
        spool_mailer:
            spool:
                type: file
                path: /path/to/spool
            # ...
        instant_mailer:
            # ... 

Then use one emailer or the other depending on whether you want to spool or not:

//in your controller
$spoolMailer = $this->get('swiftmailer.mailer.spool_mailer');
$spoolMailer->send(...);  //this will be spooled

$instantMailer = $this->get('swiftmailer.mailer.instant_mailer');
$instantMailer->send(...);  //this will be sent instantly


来源:https://stackoverflow.com/questions/33396773/send-emails-via-memory-in-controllers-and-spool-in-some-commands-in-symfony2

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