Skip to content

Commit 98d3134

Browse files
cursoragentjeboehm
andcommitted
feat: Enable Postfix Postscreen and configure Unbound DNS
Co-authored-by: j.boehm <[email protected]>
1 parent 855ef06 commit 98d3134

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

target/mta/Dockerfile

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,27 @@ RUN apk --no-cache add \
6565
postconf smtpd_error_sleep_time=10s && \
6666
postconf smtpd_soft_error_limit=3 && \
6767
postconf smtpd_hard_error_limit=5 && \
68-
newaliases
68+
newaliases && \
69+
# enable postscreen on port 25 and supporting services
70+
sed -i 's/^smtp\s\+inet\s\+n\s\+-\s\+y\s\+-\s\+-\s\+smtpd/smtp inet n - y - 1 postscreen/' /etc/postfix/master.cf && \
71+
printf '%s\n' \
72+
'smtpd pass - - y - - smtpd' \
73+
'dnsblog unix - - y - 0 dnsblog' \
74+
'tlsproxy unix - - y - 0 tlsproxy' \
75+
>> /etc/postfix/master.cf && \
76+
postconf postscreen_dnsbl_sites='bl.spamcop.net*2' && \
77+
postconf postscreen_dnsbl_threshold=2 && \
78+
postconf postscreen_dnsbl_action=enforce && \
79+
echo "submission inet n - n - - smtpd" >> /etc/postfix/master.cf && \
80+
echo " -o syslog_name=postfix/submission" >> /etc/postfix/master.cf && \
81+
echo " -o smtpd_tls_security_level=encrypt" >> /etc/postfix/master.cf && \
82+
echo " -o smtpd_sasl_auth_enable=yes" >> /etc/postfix/master.cf && \
83+
echo " -o smtpd_tls_auth_only=yes" >> /etc/postfix/master.cf && \
84+
echo " -o smtpd_reject_unlisted_recipient=no" >> /etc/postfix/master.cf && \
85+
echo " -o smtpd_sender_restrictions=reject_sender_login_mismatch,permit_sasl_authenticated,reject" >> /etc/postfix/master.cf && \
86+
echo " -o smtpd_relay_restrictions=" >> /etc/postfix/master.cf && \
87+
echo " -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject" >> /etc/postfix/master.cf && \
88+
echo " -o milter_macro_daemon_name=ORIGINATING" >> /etc/postfix/master.cf
6989
COPY --from=dockerize /bin/dockerize /usr/local/bin/dockerize
7090
COPY rootfs/ /
7191

target/mta/rootfs/usr/local/bin/init.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,23 @@ dockerize \
5555
-template /etc/postfix/mysql-recipient-access.cf.templ:/etc/postfix/mysql-recipient-access.cf \
5656
-template /etc/postfix/mysql-email-submission.cf.templ:/etc/postfix/mysql-email-submission.cf \
5757
/bin/true
58+
59+
# Configure resolver for Postfix to use $UNBOUND_DNS_ADDRESS
60+
# Accept formats like "host:port" or "ip:port"; default port 53 if omitted
61+
if [ -n "${UNBOUND_DNS_ADDRESS}" ]; then
62+
UNBOUND_DNS_HOST=$(echo "${UNBOUND_DNS_ADDRESS}" | cut -d: -f1)
63+
UNBOUND_DNS_PORT=$(echo "${UNBOUND_DNS_ADDRESS}" | cut -s -d: -f2)
64+
if [ -z "${UNBOUND_DNS_PORT}" ]; then
65+
UNBOUND_DNS_PORT=53
66+
fi
67+
68+
# Resolve hostname to IP if necessary
69+
UNBOUND_DNS_IP=$(getent hosts "${UNBOUND_DNS_HOST}" | awk '{print $1}' | head -n1)
70+
if [ -z "${UNBOUND_DNS_IP}" ]; then
71+
UNBOUND_DNS_IP=${UNBOUND_DNS_HOST}
72+
fi
73+
74+
mkdir -p /var/spool/postfix/etc
75+
echo "nameserver ${UNBOUND_DNS_IP}" > /var/spool/postfix/etc/resolv.conf
76+
# glibc resolv.conf does not support custom port; rely on Unbound standard port 53
77+
fi

0 commit comments

Comments
 (0)