如何定义一个额外的邮件服务来使用假脱机程序并在Symfony2中发送即时电子邮件 [英] How to define an additional mailer service to use the spool and send instant emails in Symfony2

查看:154
本文介绍了如何定义一个额外的邮件服务来使用假脱机程序并在Symfony2中发送即时电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Symfony2网络应用程序中,我应该发送两种电子邮件:即时和批量。即时电子邮件应该立即发送,而大量电子邮件应使用假脱机程序发送。使用Symfony2中Swiftmailer的默认配置,这是不可能的,因为只有一个邮件服务。



在这里已经提到了类似的问题(如何在其他控制器的时刻发送电子邮件(在任务中)并发送正常的电子邮件?)没有运气,但是根据这个github线程( https://github.com/symfony/SwiftmailerBundle/issues/6 )可以创建第二个邮件服务,可以配置完全不同于默认一个。有人在那里(stof)推荐作为一个可能的解决方案来遵循SwiftmailerBundle中的配置( https://github.com/symfony/SwiftmailerBundle/blob/master/Resources/config/swiftmailer.xml )来创建这个新服务,但是我不知道究竟如何。 / p>

有没有人知道如何创建一个额外的邮件服务,我可以将其配置为假脱机程序,同时让默认邮件服务发送常规(即时)电子邮件?

解决方案

我发现解决方案 here



这是我如何实现它:



首先,我配置了默认邮件服务作为假脱机程序发送大量电子邮件。



(config.yml)



swiftmailer:
transport:%mailer_transport%
加密:%mailer_encryption%
auth_mode:%mailer_auth_mode%
主机:%mailer_host%
用户名:%mailer_user%
密码:%mailer_password%
spool:
类型:文件
路径:%kernel.root_dir%线程

然后,在我的一个bundle(CommonBundle)内部,我注册了一个名为instant_mailer的新服务(/)>

(service.yml)

  instant_mailer:
class:%swiftmailer.class%
参数:[@?swiftmailer.transport.real]
/ pre>

最后,在我的控制器中,每当我想发送一封电子邮件,使用我的笔记本电话:



< pre class =lang-php prettyprint-override> $ mailer = $ this-> get('mailer');

并发送即时电子邮件:

  $ mailer = $ this-> get('instant_mailer'); 


In my Symfony2 web app I'm supposed to send two kind of emails: instant and bulk. The instant emails should be send right away while the bulk emails should be send using the spool. With the default configuration of the Swiftmailer in Symfony2 it is impossible to do that because there is only one mailer service.

Similar questions has been asked here in SO ( How to spool emails (in a task) and send normal emails in the moment in the other controllers? ) with no luck, but according to this github thread ( https://github.com/symfony/SwiftmailerBundle/issues/6 ) it is possible to create a second mailer service that can be configured totally different than the default one. Someone there (stof) recommended as a possible solution to follow the configuration found in the SwiftmailerBundle ( https://github.com/symfony/SwiftmailerBundle/blob/master/Resources/config/swiftmailer.xml ) to create this new service, but I don't know how exactly do that.

Does anyone know how to create an additional mailer service that I can configured as a spool while having the default mailer service to send regular (instant) emails?

解决方案

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');

这篇关于如何定义一个额外的邮件服务来使用假脱机程序并在Symfony2中发送即时电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆