How to spool emails (in a task) and send normal emails in the moment in the other controllers?
Asked Answered
N

3

4

In my application we send notification emails at the moment, for example, when your registry, or when need to confirm some information via email.

But also we need to send personalized emails (only differenced in one text) for a hundreds of users, but I do not know how to combine Symfony2 spool email with no spool email in the same project.

There are something like a parameter when sending the email to indicate this?

Something like $email->send('no-spool');

Nevins answered 24/5, 2012 at 16:21 Comment(3)
I opened an issue and was derived to existent one: github.com/symfony/SwiftmailerBundle/issues/7Nevins
@Ztere0 in the GitHub issue that you where redirected to (github.com/symfony/SwiftmailerBundle/issues/6) stof said that it is possible to define a second mailer service. Did you manage to do that?Pneumonoultramicroscopicsilicovolcanoconiosis
@David, not yet, but thanks by the responseNevins
P
4

I found the solution and posted here: How to define an additional mailer service to use the spool and send instant emails in Symfony2

In a nutshell:

instant_mailer:
    class: %swiftmailer.class%
    arguments: ["@?swiftmailer.transport.real"]
Pneumonoultramicroscopicsilicovolcanoconiosis answered 4/9, 2012 at 20:16 Comment(1)
Nice! But you may run into issues if one environment uses spooling and the other doesn't. You might want to check if $this->get('mailer')->getTransport() instanceof \Swift_Transport_SpoolTransport before switching to the .real transport since it may not exist!Transversal
N
0

PEAR::Mail_Queue http://pear.php.net/package/Mail_Queue is specifically designed for spooling large amounts of mail to be sent. so i would use this specifically for all your non urgent messages and then use the general mail function or even Pear::Mail for the immediate ones.

Nitaniter answered 21/7, 2012 at 0:34 Comment(0)
S
-2

According to the Symfony 1.4 documentation, you can use a the following call to send a message immediately (when you are using a spool strategy for the project overall):

$this->getMailer()->sendNextImmediately()->send($message);

This is a lot simpler than the accepted answer, and will be the correct solution if you do not need to send many spooled messages. I'd imagine the same, or a similar function exists in symfony2.

http://www.symfony-project.org/gentle-introduction/1_4/en/11-Emails

Simpleton answered 25/9, 2012 at 17:2 Comment(1)
The same thing does not exist in sf2 and the accepted answer isn't that much complicated.Transversal

© 2022 - 2024 — McMap. All rights reserved.