From 22f46669dbdd35b82aabcf1abbf63be04941e9be Mon Sep 17 00:00:00 2001 From: turboaaa Date: Tue, 8 Jan 2019 18:12:45 -0500 Subject: [PATCH 1/5] Replace add_config_value with native postconf This project saved me a lot of time. With the basic service running in docker I was able to add TLS and authentication for external clients. I am hoping I can help in some small way. --- run.sh | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/run.sh b/run.sh index aa1ff7d..673ac3d 100644 --- a/run.sh +++ b/run.sh @@ -2,19 +2,6 @@ [ "${DEBUG}" == "yes" ] && set -x -function add_config_value() { - local key=${1} - local value=${2} - local config_file=${3:-/etc/postfix/main.cf} - [ "${key}" == "" ] && echo "ERROR: No key set !!" && exit 1 - [ "${value}" == "" ] && echo "ERROR: No value set !!" && exit 1 - - echo "Setting configuration option ${key} with value: ${value}" - sed -i -e "/^#\?\(\s*${key}\s*=\s*\).*/{s//\1${value}/;:a;n;:ba;q}" \ - -e "\$a${key}=${value}" \ - ${config_file} -} - [ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1 [ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1 [ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1 @@ -26,15 +13,16 @@ SMTP_PORT="${SMTP_PORT-587}" DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'` # Set needed config options -add_config_value "myhostname" ${SERVER_HOSTNAME} -add_config_value "mydomain" ${DOMAIN} -add_config_value "mydestination" '$myhostname' -add_config_value "myorigin" '$mydomain' -add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}" -add_config_value "smtp_use_tls" "yes" -add_config_value "smtp_sasl_auth_enable" "yes" -add_config_value "smtp_sasl_password_maps" "hash:\/etc\/postfix\/sasl_passwd" -add_config_value "smtp_sasl_security_options" "noanonymous" +postconf -e "myhostname = ${SERVER_HOSTNAME}" +postconf -e "mydomain = ${DOMAIN}" +postconf -e "mydestination = $myhostname" +postconf -e "myorigin = \$mydomain" +postconf -e "relayhost = [${SMTP_SERVER}]:${SMTP_PORT}" +postconf -e "smtp_use_tls = yes" +postconf -e "smtp_sasl_auth_enable = yes" +postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" +postconf -e "smtp_sasl_security_options = noanonymous" +postconf -e "smtp_sasl_tls_security_options = noanonymous" # Create sasl_passwd file with auth credentials if [ ! -f /etc/postfix/sasl_passwd ]; then From d3f3316ccf3a8cefb7b23c2f03b7b8f50ac680ee Mon Sep 17 00:00:00 2001 From: turboaaa Date: Wed, 16 Jan 2019 13:09:56 -0500 Subject: [PATCH 2/5] Update run.sh Formatting. --- run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 673ac3d..feffb57 100644 --- a/run.sh +++ b/run.sh @@ -15,8 +15,8 @@ DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^ # Set needed config options postconf -e "myhostname = ${SERVER_HOSTNAME}" postconf -e "mydomain = ${DOMAIN}" -postconf -e "mydestination = $myhostname" -postconf -e "myorigin = \$mydomain" +postconf -e 'mydestination = $myhostname' +postconf -e 'myorigin = $mydomain' postconf -e "relayhost = [${SMTP_SERVER}]:${SMTP_PORT}" postconf -e "smtp_use_tls = yes" postconf -e "smtp_sasl_auth_enable = yes" From 640b29d0884b9abd908e9633241041a7672f1b5c Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sun, 20 Jan 2019 00:01:55 -0500 Subject: [PATCH 3/5] Update run.sh --- run.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/run.sh b/run.sh index feffb57..174196d 100644 --- a/run.sh +++ b/run.sh @@ -22,7 +22,6 @@ postconf -e "smtp_use_tls = yes" postconf -e "smtp_sasl_auth_enable = yes" postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" postconf -e "smtp_sasl_security_options = noanonymous" -postconf -e "smtp_sasl_tls_security_options = noanonymous" # Create sasl_passwd file with auth credentials if [ ! -f /etc/postfix/sasl_passwd ]; then From 25f561db6b4add8ffaa99fb25f53dbe34774f7fd Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sun, 17 Feb 2019 12:50:21 -0500 Subject: [PATCH 4/5] Convert previous function to using postfix. --- run.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/run.sh b/run.sh index 174196d..63fdbd1 100644 --- a/run.sh +++ b/run.sh @@ -2,6 +2,18 @@ [ "${DEBUG}" == "yes" ] && set -x +function add_config_value() { + local key=${1} + local value=${2} + local config_file=${3:-/etc/postfix/main.cf} + [ "${key}" == "" ] && echo "ERROR: No key set !!" && exit 1 + [ "${value}" == "" ] && echo "ERROR: No value set !!" && exit 1 + + echo "Setting configuration option ${key} with value: ${value}" + postconf -e "${key} = ${value}" +} + + [ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1 [ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1 [ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1 @@ -13,15 +25,16 @@ SMTP_PORT="${SMTP_PORT-587}" DOMAIN=`echo ${SERVER_HOSTNAME} |awk -F. '{$1="";OFS="." ; print $0}' | sed 's/^.//'` # Set needed config options -postconf -e "myhostname = ${SERVER_HOSTNAME}" -postconf -e "mydomain = ${DOMAIN}" -postconf -e 'mydestination = $myhostname' -postconf -e 'myorigin = $mydomain' -postconf -e "relayhost = [${SMTP_SERVER}]:${SMTP_PORT}" -postconf -e "smtp_use_tls = yes" -postconf -e "smtp_sasl_auth_enable = yes" -postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" -postconf -e "smtp_sasl_security_options = noanonymous" +add_config_value "myhostname" ${SERVER_HOSTNAME} +add_config_value "mydomain" ${DOMAIN} +add_config_value "mydestination" '$myhostname' +add_config_value "myorigin" '$mydomain' +add_config_value "relayhost" "[${SMTP_SERVER}]:${SMTP_PORT}" +add_config_value "smtp_use_tls" "yes" +add_config_value "smtp_sasl_auth_enable" "yes" +add_config_value "smtp_sasl_password_maps" "hash:\/etc\/postfix\/sasl_passwd" +add_config_value "smtp_sasl_security_options" "noanonymous" + # Create sasl_passwd file with auth credentials if [ ! -f /etc/postfix/sasl_passwd ]; then From 132deee541bc141685879d045d8fdadaae3ec0fa Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sun, 17 Feb 2019 12:50:55 -0500 Subject: [PATCH 5/5] Update run.sh --- run.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/run.sh b/run.sh index 63fdbd1..5b6bbb6 100644 --- a/run.sh +++ b/run.sh @@ -13,7 +13,6 @@ function add_config_value() { postconf -e "${key} = ${value}" } - [ -z "${SMTP_SERVER}" ] && echo "SMTP_SERVER is not set" && exit 1 [ -z "${SMTP_USERNAME}" ] && echo "SMTP_USERNAME is not set" && exit 1 [ -z "${SMTP_PASSWORD}" ] && echo "SMTP_PASSWORD is not set" && exit 1 @@ -35,7 +34,6 @@ add_config_value "smtp_sasl_auth_enable" "yes" add_config_value "smtp_sasl_password_maps" "hash:\/etc\/postfix\/sasl_passwd" add_config_value "smtp_sasl_security_options" "noanonymous" - # Create sasl_passwd file with auth credentials if [ ! -f /etc/postfix/sasl_passwd ]; then grep -q "${SMTP_SERVER}" /etc/postfix/sasl_passwd > /dev/null 2>&1