diff --git a/README.md b/README.md index 8401284..57aacd2 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,22 @@ Stripping sender details SMF will strip the sender's IP, client, and user agent headers when the `SMF_SENDERPRIVACY` environment variable is defined. + +Custom postfix configuration +---------------------------- + +SMF allows to use environment variables to add or change lines to postfix `main.cf` and `master.cf` configuration files. + +- `SMF_POSTFIXMAIN_*` variables will edit postfix `main.cf` entries. + - Format: `SMF_POSTFIXMAIN_option_name=value` + - Example: `SMF_POSTFIXMAIN_soft_bounce=yes` will call `postconf -e soft_bounce=yes` and add the option. + +- `SMF_POSTFIXMASTER_*` variables will edit postfix `master.cf`. + - Format: `SMF_POSTFIXMASTER_service__name__type__parameter_name=value` Please note the double underscore `__` to differentiate service and type (which require a `/` as separation symbol) and the single underscore `_` used only by parameter names. + - Example: `SMF_POSTFIXMASTER_submission__inet__smtpd__recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject` will call `postconf -P submission/inet/smtpd/recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject` and add the option. + + + Helper Scripts -------------------- diff --git a/VERSION b/VERSION index 347f583..9df886c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.1 +1.4.2 diff --git a/entrypoint.sh b/entrypoint.sh index 8523947..62e58f8 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -20,6 +20,8 @@ Environment Variables: SMF_MYNETWORKS - configure relaying from trusted IPs, see http://www.postfix.org/postconf.5.html#mynetworks SMF_RELAYHOST - configure a relayhost SMF_SENDERPRIVACY - strips sender's IP, client, and user agent. + SMF_POSTFIXMAIN_* - configure any postfix main.cf variable + SMF_POSTFIXMASTER_* - configure any postfix master.cf variable this creates a new smtp server which listens on port 25, forward all email from @@ -257,6 +259,21 @@ function start_postfix { echo "InternalHosts /etc/opendkim/TrustedHosts" >> /etc/opendkim/opendkim.conf fi + echo "Postfix main.cf custom entries from SMF_POSTFIXMAIN_" + # Allow for setting any Postfix variables in the main.cf file through environment variables. + for e in ${!SMF_POSTFIXMAIN_*} ; do + OPT_NAME=$(echo ${e:16} | tr '[:upper:]' '[:lower:]') + OPT_VALUE=${!e} + echo "postconf -e "${OPT_NAME}=${OPT_VALUE}"" + postconf -e "${OPT_NAME}=${OPT_VALUE}" + done + echo "Postfix master.cf custom entries from SMF_POSTFIXMASTER_" + # Allow for setting any Postfix variables in the master.cf file through environment variables. + for e in ${!SMF_POSTFIXMASTER_*} ; do + OPT_NAME=$(echo ${e:18} | tr '[:upper:]' '[:lower:]' | sed 's/__/\//g') + OPT_VALUE=${!e} + postconf -P "${OPT_NAME}=${OPT_VALUE}" + done } # diff --git a/test/simple-mail-forwarder.bats b/test/simple-mail-forwarder.bats index 015658b..843bd15 100644 --- a/test/simple-mail-forwarder.bats +++ b/test/simple-mail-forwarder.bats @@ -183,3 +183,21 @@ done [ $? -eq 0 ] } + +@test "test custom main.cf entries" { + for e in ${!SMF_POSTFIXMAIN_*} ; do + OPT_NAME=$(echo ${e:16} | tr '[:upper:]' '[:lower:]') + OPT_VALUE=${!e} + ret=$(postconf | grep "$OPT_NAME" | grep "$OPT_VALUE") + [[ ! -z "$ret" ]] + done +} + +@test "test custom master.cf entries" { + for e in ${!SMF_POSTFIXMASTER_*} ; do + OPT_NAME=$(echo ${e:18} | tr '[:upper:]' '[:lower:]' | sed 's/__/\//g') + OPT_VALUE=${!e} + ret=$(postconf -P | grep "$OPT_NAME" | grep "$OPT_VALUE") + [[ ! -z "$ret" ]] + done +}