docker-postfix icon indicating copy to clipboard operation
docker-postfix copied to clipboard

Add support for setting arbitrary postfix configuration values

Open telmich opened this issue 2 years ago • 3 comments

Situation

Postfix has a lot of options and it is hard/impossible to support all of them in the image. However, we can add rather generic support for any kind of option the following way.

Looking for POSTFIX_* and setting it

I suggest to add to run.sh something on the line of:

for var in $(set | grep POSTFIX_); do
   keyname=${var#POSTFIX_}
   eval value=\$$var
  postconf -e "$keyname = $value"
done

This should work for arbitrary values .

telmich avatar Apr 23 '22 10:04 telmich

I'd echo the request but beyond just variables.

I wanted to add some custom header re-writes due to n HP printer issue. I ended up mounting a path within the docker with script.sh and executing the script via scheduled docker exec.

Maybe it's worth adding a line in run.sh that checks for presence of an /external/script.sh and executes it if it's present? That way users can simply add their postconf commands, echo, etc. to script.sh and it gets run on compose?

Speeder2000 avatar Apr 26 '22 22:04 Speeder2000

Hi @telmich and @Speeder2000, thanks for your input.

This container started as a simple way to use a relay to allow docker containers to send email, but it has grown beyond that goal since then. I agree that it would be nice to make this image more generic to allow it to be used in more use cases, but we should not make it more complex to use.

This means that current configuration cannot be broken, the image must continue to work as it currently does, to avoid breaking current installations. For example, handling of cases where there is already an env variable for a config option, but it is also present in a custom configuration variable.

Currently, I do not have the time to work on this, if you are willing to send a PR implementing this, prior to a discussion on how you plan on doing it, I will be happy to review it and then merge it.

juanluisbaptiste avatar May 13 '22 14:05 juanluisbaptiste

Hi,

I took a shot at improving @telmich suggestion.

This should be working. It will make keyname lowercase. So, e.g., POSTFIX_VIRTUAL_TRANSPORT=xyz becomes virtual_transport = xyz

for var in "${!POSTFIX_@}"; do
    keyname=$(echo ${var#POSTFIX_} | tr '[:upper:]' '[:lower:]')
    value=${!var}
    postconf -e "$keyname = $value"
done

If we want to avoid these POSTFIX_ environment variables overwriting any of the existing environment variables we could have a list of reserved keynames and check against that one before calling postconf.

flojon avatar Jul 23 '22 10:07 flojon