exim4 says "Warning: purging the environment" even though add/keep_environment are set

Solution 1:

exim4 -bP will only show you currently used values, including the the ones exim4 itself set up to defaults after outputing the warnings.

You should check with grep -r keep_environment /etc/exim4 to see if it is indeed active in your config file. It should be in /etc/exim4/exim4.conf if you use that. If you have /etc/exim4/exim4.conf but the option is in /etc/exim4/exim4.conf.template, you may need to add it manually or use update-exim4.conf(8).

You can find more info here

Solution 2:

You can't tell if an option is not set or has no value from exim -bP output. Since the latter simply iterates all the available options and prints their values.

Most likely one of the servers has keep_environment option in its config. Places to check are /etc/exim4 and /var/lib/exim4/config.autogenerated.

The option was introduced to circumvent a certain security threat. The fix was made in 4.86.2. But also backported to 4.84.2. Both Jessie and Stretch have it. It cleans the environment according to keep_environment, add_environment options. If keep_environment is not set, it logs a warning and suggests to add it. Since exim might be configured in a way that needs to keep some environment variables. Which is not the case on Debian with the default config. So on Debian normally it can be set to empty value.

And at some point the option was added to the config (4.87--RC6-3). But it was in Debian Stretch. That's unlikely to be backpoirted to Jessie, since it is no security issue.

The solution is to add it to /etc/exim4/exim4.conf.localmacros manually:

keep_environment =

Then:

update-exim4.conf
systemctl reload exim4