juanluisbaptiste / docker-postfix

Simple SMTP relay docker image.
GNU General Public License v3.0
336 stars 166 forks source link

Add support for setting arbitrary postfix configuration values #80

Open telmich opened 2 years ago

telmich commented 2 years ago

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 .

Speeder2000 commented 2 years ago

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?

juanluisbaptiste commented 2 years ago

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.

flojon commented 2 years ago

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.

shalak commented 1 month ago

Any updates on this? This would be a really handy feature 🤔