From e7eb0a9d8eca8494c46f717cbdc9483e0db8e390 Mon Sep 17 00:00:00 2001 From: turboaaa Date: Wed, 16 Jan 2019 12:34:48 -0500 Subject: [PATCH 1/7] Add header tag creation. This will create a tag in email headers that can be used for filtering by receiving servers. I use this image for relaying through exchange online, and the nature of how I run my containers prevents me from setting static IPs as a filter. With a tag for exchange to look at, I can make sure emails from the relay are not hitting the junk folder. Without setting the HEADER_TAG variable, the script will create a randomly generated tag and move on. It is not a requirement to make use of this feature. --- run.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/run.sh b/run.sh index aa1ff7d..e274251 100644 --- a/run.sh +++ b/run.sh @@ -46,5 +46,26 @@ if [ ! -f /etc/postfix/sasl_passwd ]; then fi fi +#Set header tag +postconf -e "header_checks = regexp:/etc/postfix/header_tag" +if [ -z "${HEADER_TAG}" ]; then +TAG="$RANDOM" +else +TAG="${HEADER_TAG}" +fi +echo -e "/^MIME-Version:/i PREPEND RelayTag: $TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $TAG" > /etc/postfix/header_tag +echo "******** Header tag is $TAG *********" + +# 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 + if [ $? -gt 0 ]; then + echo "Adding SASL authentication configuration" + echo "[${SMTP_SERVER}]:${SMTP_PORT} ${SMTP_USERNAME}:${SMTP_PASSWORD}" >> /etc/postfix/sasl_passwd + postmap /etc/postfix/sasl_passwd + fi +fi + + #Start services supervisord From dff4a29a812192acd31cb0c88f8f6acea234caf9 Mon Sep 17 00:00:00 2001 From: turboaaa Date: Wed, 16 Jan 2019 12:38:15 -0500 Subject: [PATCH 2/7] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d6ca131..f4574d5 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ The following env variables need to be passed to the container: * `SMTP_PASSWORD` Password of the SMTP user. * `SERVER_HOSTNAME` Server hostname for the Postfix container. Emails will appear to come from the hostname's domain. +The following env variable(s) are optional. +* `HEADER_TAG` This will add a header for tracking messages upstream. Helpful for spam filters. Will appear as "RelayTag: ${HEADER_TAG}" in the email headers. + To use this container from anywhere, the 25 port needs to be exposed to the docker host server: docker run -d --name postfix -p "25:25" \ From 423c51f9a046e15f51345c0518da08935856600e Mon Sep 17 00:00:00 2001 From: turboaaa Date: Wed, 16 Jan 2019 12:39:55 -0500 Subject: [PATCH 3/7] Update run.sh --- run.sh | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/run.sh b/run.sh index e274251..3a3e22c 100644 --- a/run.sh +++ b/run.sh @@ -56,16 +56,5 @@ fi echo -e "/^MIME-Version:/i PREPEND RelayTag: $TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $TAG" > /etc/postfix/header_tag echo "******** Header tag is $TAG *********" -# 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 - if [ $? -gt 0 ]; then - echo "Adding SASL authentication configuration" - echo "[${SMTP_SERVER}]:${SMTP_PORT} ${SMTP_USERNAME}:${SMTP_PASSWORD}" >> /etc/postfix/sasl_passwd - postmap /etc/postfix/sasl_passwd - fi -fi - - #Start services supervisord From b8e54449568e4b8eec0d5dcfe5f71124acb55ae3 Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sat, 19 Jan 2019 23:55:18 -0500 Subject: [PATCH 4/7] Update README.md Updated variable name. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4574d5..5e0ae1d 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ The following env variables need to be passed to the container: * `SERVER_HOSTNAME` Server hostname for the Postfix container. Emails will appear to come from the hostname's domain. The following env variable(s) are optional. -* `HEADER_TAG` This will add a header for tracking messages upstream. Helpful for spam filters. Will appear as "RelayTag: ${HEADER_TAG}" in the email headers. +* `SMTP_HEADER_TAG` This will add a header for tracking messages upstream. Helpful for spam filters. Will appear as "RelayTag: ${SMTP_HEADER_TAG}" in the email headers. To use this container from anywhere, the 25 port needs to be exposed to the docker host server: From 630b283eea4b7ba0916a818e63fb540635ce602f Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sat, 19 Jan 2019 23:58:15 -0500 Subject: [PATCH 5/7] Update run.sh Updated header tag variable. Configured to only set the header tag if variable is set. --- run.sh | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/run.sh b/run.sh index 3a3e22c..0dc5232 100644 --- a/run.sh +++ b/run.sh @@ -47,14 +47,11 @@ if [ ! -f /etc/postfix/sasl_passwd ]; then fi #Set header tag -postconf -e "header_checks = regexp:/etc/postfix/header_tag" -if [ -z "${HEADER_TAG}" ]; then -TAG="$RANDOM" -else -TAG="${HEADER_TAG}" +if [ -z "${SMTP_HEADER_TAG}" ]; then + postconf -e "header_checks = regexp:/etc/postfix/header_tag" + echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" > /etc/postfix/header_tag + echo "******** Header tag is $SMTP_HEADER_TAG *********" fi -echo -e "/^MIME-Version:/i PREPEND RelayTag: $TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $TAG" > /etc/postfix/header_tag -echo "******** Header tag is $TAG *********" #Start services supervisord From 3949dcefc00d383dfeac605c808fb044f4847e63 Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sat, 26 Jan 2019 17:12:50 -0500 Subject: [PATCH 6/7] Update run.sh --- run.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.sh b/run.sh index 0dc5232..46763cb 100644 --- a/run.sh +++ b/run.sh @@ -46,11 +46,11 @@ if [ ! -f /etc/postfix/sasl_passwd ]; then fi fi -#Set header tag +#Set header tag if [ -z "${SMTP_HEADER_TAG}" ]; then postconf -e "header_checks = regexp:/etc/postfix/header_tag" echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" > /etc/postfix/header_tag - echo "******** Header tag is $SMTP_HEADER_TAG *********" + echo "Setting configuration option SMTP_HEADER_TAG with value: ${SMTP_HEADER_TAG}" fi #Start services From 3196395b4ee89d33b6fe8b4e0189f2d2d2f2207c Mon Sep 17 00:00:00 2001 From: turboaaa Date: Sat, 26 Jan 2019 20:50:34 -0500 Subject: [PATCH 7/7] Update run.sh --- run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.sh b/run.sh index 46763cb..49daade 100644 --- a/run.sh +++ b/run.sh @@ -47,7 +47,7 @@ if [ ! -f /etc/postfix/sasl_passwd ]; then fi #Set header tag -if [ -z "${SMTP_HEADER_TAG}" ]; then +if [ ! -z "${SMTP_HEADER_TAG}" ]; then postconf -e "header_checks = regexp:/etc/postfix/header_tag" echo -e "/^MIME-Version:/i PREPEND RelayTag: $SMTP_HEADER_TAG\n/^Content-Transfer-Encoding:/i PREPEND RelayTag: $SMTP_HEADER_TAG" > /etc/postfix/header_tag echo "Setting configuration option SMTP_HEADER_TAG with value: ${SMTP_HEADER_TAG}"