0

I'm using Symfony 2.7 which comes with SwiftmailerBundle 2.3.8.

This is my configuration

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

I want to use 2 mailers, one for spooling and one for sending them instantly.

These two commands will work just fine, the email is either spooled or sent instantly.

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

However,

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

Doesn't fetch the default_mailer which is the spooler in my case, but it sends it instantly. I've seen here that this is possible, but maybe that answer is incorrect.

Did I miss something in the configuration file? Or am I not calling it right?

Community
  • 1
  • 1
George Irimiciuc
  • 4,573
  • 8
  • 44
  • 88
  • I **really donno** why but I have seen that declaring the `default_mailer: spool_mailer` line above defining the mailers will do it. I don't have any supporting docs for this too. But it is worthy trying I believe. – Himel Nag Rana Apr 25 '16 at 10:20

1 Answers1

0

I run into the same problem, even though using symfony version 2.6.8. The only solution I found at this moment is: remove the default_mailer parameter, and set the default mailer with such name, this is: default. So your configuration would be like:

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%"

From now the object gotten from $this->getContainer()->get('swiftmailer.mailer'); will be the one defined as default and NO more errors like this will be shown:

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

This configuration worked for me in the project I am currently working on.

I hope it helps.

Samuel Vicent
  • 991
  • 10
  • 16