Skip to content
This repository was archived by the owner on Feb 6, 2022. It is now read-only.

Using an env var for the disable_delivery option doesn't work as expected #290

Closed
samfahmie opened this issue Aug 3, 2019 · 4 comments
Closed

Comments

@samfahmie
Copy link

When using a configuration like this:

swiftmailer:
    disable_delivery: "%env(TEST_MAIL_DISABLE_DELIVERY)%"
    # send all emails to a specific address
    delivery_addresses:
        - "%env(TEST_MAIL_DELIVERY_ADDRESS)%"

the value of TEST_MAIL_DISABLE_DELIVERY is ignored, and delivery is always disabled. Furthermore, if that env var isn't used anywhere else, the container will fail to build saying that this variable is unused.

The only solution I have right now is use php for the configuration, parse out the env value manually, and assign the value that way. But, this setting should use the env var value like any other.

@weaverryan
Copy link
Member

Probably that value is read at container build time to change a service definition. It would likely require some reworking so that it’s read at runtime.

@samfahmie
Copy link
Author

That's what my analysis showed. I was going to try to create a simple fix and just submit a PR but it looks like the way to solve it likely involves storing the value in parameters and referencing it at runtime when attempting to send mail instead.

@arno14
Copy link

arno14 commented Sep 17, 2019

I have not been able to disable/enable mail delivery with Env vars on a project with Symfony 4.3.4
file .env

SWIFTMAILER_DISABLE_DELIVERY=1

file config/packages/swiftmailer.yml

swiftmailer:
    disable_delivery: '%mailer_disable_delivery%'  

file config/services.yml

parameters:
    swiftmailer_disable_delivery: "%env(bool:SWIFTMAILER_DISABLE_DELIVERY)%"

This config does not work.
Even if calling $container->getParameter('swiftmailer_disable_delivery') return the correct value regarding the env vars.
When processing config, the swiftmailer bundle always consider that this value is true (as it is a string whose content is "%env...", see https://github.com/symfony/swiftmailer-bundle/blob/master/DependencyInjection/SwiftmailerExtension.php#L83.)

I solved the problem in creating the parameter in a php file( and removing the parameter from services.yml).

file config/services.php

<?php
$container->setParameter('swiftmailer_disable_delivery', (bool)getenv('SWIFTMAILER_DISABLE_DELIVERY'));

This require to clear the cache.
An other solution would be to create a good old file called "parameters.yml" that would not be commited (in addition to the also uncommited ".env.local" file).

@fabpot
Copy link
Member

fabpot commented Feb 6, 2022

Closing as this bundle is not maintained anymore.

@fabpot fabpot closed this as completed Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants