Disable swiftmailer spool in Symfony per environment
Asked Answered
T

1

12

I having trouble send bulk emails with symfony2 via console command. I want to disable the mail spooling complete for the env the console is running in but keep it working for the default env. So I have this in config.yml:

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    port:      %mailer_port%
    username:  %mailer_user%
    password:  %mailer_password%
    spool:     %mailer_spool_type%

and then each env has it's on parameters like parameters_prod.yml:

parameters:
    mailer_transport:       smtp
    mailer_host:            smtp.someserver.net
    mailer_port:            587
    mailer_user:            "someuser"
    mailer_password:        "somepassword"
    mailer_spool_type:      { type:memory }

then for the console env I use parameters_cron.yml:

parameters:    
    mailer_spool_type: ~

The problem is using ~ or null doesn't actually turn off the spool but it uses the default values of {cache: file, path: %kernel.cache_dir%/swiftmailer/spool }

Is there a way to disable the spool just by changing the parameters or is there a better way?

Topheavy answered 24/2, 2014 at 23:0 Comment(1)
Any feedback ? Did my solution work for you?Corcoran
R
24

Apparently the only way to disable email spooling is to completely leave out the spool entry from your configuration file. Once you include the spool entry in the main configuration file, there is no way to disable spooling for a specific environment.

That said, you can accomplish the opposite of what you propose: you can disable email spooling by default and enable it in specific environments.

Leave it out in config.yml:

swiftmailer:
    transport: %mailer_transport%
    host:      %mailer_host%
    port:      %mailer_port%
    username:  %mailer_user%
    password:  %mailer_password%

And include it in config_prod.yml:

swiftmailer:
    spool:     %mailer_spool_type%
Ropy answered 16/1, 2015 at 22:26 Comment(2)
This is the only currently the only feasible method to disable the spooling.Lanni
in symfony 4.2 you need t comment spool line in swiftmailer.yamlPneumatology

© 2022 - 2024 — McMap. All rights reserved.