From e7eb0a9d8eca8494c46f717cbdc9483e0db8e390 Mon Sep 17 00:00:00 2001 From: turboaaa Date: Wed, 16 Jan 2019 12:34:48 -0500 Subject: [PATCH] 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