Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for setting any Postfix variables in the config file (both main.cf and master.cf) #93

Merged
merged 11 commits into from
Feb 23, 2021
Merged
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.4.2
17 changes: 17 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

#
Expand Down
18 changes: 18 additions & 0 deletions test/simple-mail-forwarder.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
}