0

我正在使用 SwiftmailerBundle 2.3.8 附带的 Symfony 2.7。

这是我的配置

swiftmailer:
    mailers:
        spool_mailer:
            transport: "%mailer_transport%"
            host:      "%mailer_host%"
            username:  "%mailer_user%"
            password:  "%mailer_password%"
            spool:
                type: file
                path: %kernel.root_dir%/spool

        instant_mailer:
            transport: "%mailer_transport%"
            host:      "%mailer_host%"
            username:  "%mailer_user%"
            password:  "%mailer_password%"
    default_mailer: spool_mailer

我想使用 2 个邮件程序,一个用于假脱机,一个用于立即发送。

这两个命令可以正常工作,电子邮件要么被假脱机,要么立即发送。

 $this->get('swiftmailer.mailer.instant_mailer')->send($email);
 $this->get('swiftmailer.mailer.spool_mailer')->send($email);

然而,

  $this->get('mailer')->send($email);

在我的情况下不获取default_mailer哪个是假脱机程序,但它会立即发送。我在这里看到这是可能的,但也许这个答案是不正确的。

我错过了配置文件中的某些内容吗?还是我说的不对?

4

1 回答 1

0

即使使用 symfony 2.6.8 版,我也遇到了同样的问题。我目前找到的唯一解决方案是:删除 default_mailer 参数,并使用这样的名称设置默认邮件程序,即:default。所以你的配置会是这样的:

swiftmailer:
    mailers:
        default: # your named spool_mailer
            transport: "%mailer_transport%"
            host:      "%mailer_host%"
            username:  "%mailer_user%"
            password:  "%mailer_password%"
            spool:
                type: file
                path: %kernel.root_dir%/spool

        instant_mailer:
            transport: "%mailer_transport%"
            host:      "%mailer_host%"
            username:  "%mailer_user%"
            password:  "%mailer_password%"

从现在开始,对象从 $this->getContainer()->get('swiftmailer.mailer'); 将被定义为默认值,并且不会显示更多这样的错误:

[Swift_TransportException]                                                         
  Connection could not be established with host localhost [Connection refused #111] 

此配置在我目前正在处理的项目中对我有用。

我希望它有所帮助。

于 2016-04-25T10:06:46.780 回答