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

通过控制器中的内存和Symfony2中的某些命令中的假脱机发送电子邮件,symfony,email,memory,swiftmailer,spool,Symfony,Email,Memory,Swiftmailer,Spool,我需要使用spool选项向我的用户发送大量电子邮件,但我不会将我的应用程序的整个配置更改为spool,因为我的注册系统会向用户发送电子邮件,并且我希望此电子邮件是即时发送的 有没有办法在不更改swiftmailer的全局配置的情况下执行此操作?您可以配置不同的电子邮件发送程序。例如: swiftmailer: default_mailer: spool_mailer mailers: spool_mailer: spool:

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


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

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

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