Support for setting relayhost in main.cf (#1104)

* Added DEFAULT_RELAY_HOST setting
* If set this value will be used as the relayhost in /etc/postfix/maincf causing all mail to be delivered using this relay host
* Test for default relay host setting
This commit is contained in:
jjtt 2019-01-19 12:10:31 +02:00 committed by Johan Smits
parent 1302ccfe7e
commit a3724fa91d
6 changed files with 49 additions and 1 deletions

View file

@ -305,6 +305,16 @@ SRS_EXCLUDE_DOMAINS=
# rotate and expire keys
SRS_SECRET=
# -----------------------------------------------------------------------------------------------------------------------------
# ---------------- Default relay host section ---------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------------------
# Setup relaying all mail through a default relay host
#
# empty => don't configure default relay host
# default host and optional port to relay all mail through
DEFAULT_RELAY_HOST=
# -----------------------------------------------------------------------------------------------------------------------------
# ---------------- Multi-domain relay section ---------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------------------------------------

View file

@ -244,6 +244,15 @@ run:
-e DMS_DEBUG=0 \
-h mail.my-domain.com -t $(NAME)
sleep 15
docker run -d --name mail_with_default_relay \
-v "`pwd`/test/config/relay-hosts":/tmp/docker-mailserver \
-v "`pwd`/test":/tmp/docker-mailserver-test \
-e DEFAULT_RELAY_HOST=default.relay.host.invalid:25 \
--cap-add=SYS_PTRACE \
-e PERMIT_DOCKER=host \
-e DMS_DEBUG=0 \
-h mail.my-domain.com -t $(NAME)
sleep 15
generate-accounts-after-run:
docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
@ -309,7 +318,8 @@ clean:
mail_override_hostname \
mail_domainname \
mail_srs_domainname \
mail_with_relays
mail_with_relays \
mail_with_default_relay
@if [ -d config.bak ]; then\
rm -rf config ;\

View file

@ -586,6 +586,13 @@ Note: This postgrey setting needs `ENABLE_POSTGREY=1`
- **empty** => Derived from OVERRIDE_HOSTNAME, DOMAINNAME, or the container's hostname
- Set this if auto-detection fails, isn't what you want, or you wish to have a separate container handle DSNs
## Default Relay Host
#### DEFAULT_RELAY_HOST
- **empty** => don't set default relayhost setting in main.cf
- default host and port to relay all mail through
## Multi-domain Relay Hosts
#### RELAY_HOST

View file

@ -77,6 +77,7 @@ services:
- SASL_PASSWD=${SASL_PASSWD}
- SRS_EXCLUDE_DOMAINS=${SRS_EXCLUDE_DOMAINS}
- SRS_SECRET=${SRS_SECRET}
- DEFAULT_RELAY_HOST=${DEFAULT_RELAY_HOST}
- RELAY_HOST=${RELAY_HOST}
- RELAY_PORT=${RELAY_PORT}
- RELAY_USER=${RELAY_USER}

View file

@ -145,6 +145,10 @@ function register_functions() {
_register_setup_function "_setup_postfix_relay_hosts"
fi
if [ ! -z "$DEFAULT_RELAY_HOST" ]; then
_register_setup_function "_setup_postfix_default_relay_host"
fi
if [ ! -z "$RELAY_HOST" ]; then
_register_setup_function "_setup_postfix_relay_hosts"
fi
@ -1066,6 +1070,13 @@ function _setup_postfix_sasl_password() {
fi
}
function _setup_postfix_default_relay_host() {
notify 'task' 'Applying default relay host to Postfix'
notify 'inf' "Applying default relay host $DEFAULT_RELAY_HOST to /etc/postfix/main.cf"
postconf -e "relayhost = $DEFAULT_RELAY_HOST"
}
function _setup_postfix_relay_hosts() {
notify 'task' 'Setting up Postfix Relay Hosts'
# copy old AWS_SES variables to new variables

View file

@ -1748,6 +1748,15 @@ load 'test_helper/bats-assert/load'
assert_success
}
#
# default relay host
#
@test "checking default relay host: default relay host is added to main.cf" {
run docker exec mail_with_default_relay /bin/sh -c 'grep -e "^relayhost = default.relay.host.invalid:25" /etc/postfix/main.cf | wc -l | grep 1'
assert_success
}
#
# relay hosts
#