在Symfony2中的某些命令中通过控制器和假脱机中的内存发送电子邮件

时间:2015-10-28 16:43:32

标签: symfony email memory swiftmailer spool

我需要使用spool选项向我的用户发送大量电子邮件,但我不会将我的应用程序的整个配置更改为假脱机因为我的注册系统向用户发送电子邮件,我希望此电子邮件是即时的发送。

有没有办法在不更改swiftmailer的全局配置的情况下执行此操作?

1 个答案:

答案 0 :(得分:6)

您可以配置不同的电子邮件。例如:

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

然后使用一个电子邮件或另一个,具体取决于您是否要假脱机:

//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