1818set -eo pipefail
1919
2020echo " Configuring postfix with any environment variables that are set"
21+
2122if [[ -n " ${POSTFIX_MYNETWORKS} " ]]; then
2223 echo " Setting custom 'mynetworks' to '${POSTFIX_MYNETWORKS} '"
2324 postconf mynetworks=" ${POSTFIX_MYNETWORKS} "
2829
2930if [[ -n " ${POSTFIX_RELAYHOST} " ]]; then
3031 echo " Setting custom 'relayhost' to '${POSTFIX_RELAYHOST} '"
31- postconf relayhost=" ${POSTFIX_RELAYHOST} "
32+ postconf relayhost=" [ ${POSTFIX_RELAYHOST} ]: ${POSTFIX_RELAYHOST_PORT }"
3233else
3334 echo " Revert 'relayhost' to default (unset)"
3435 postconf -# relayhost
@@ -38,5 +39,35 @@ echo "Disable chroot for the smtp service"
3839postconf -F smtp/inet/chroot=n
3940postconf -F smtp/unix/chroot=n
4041
42+ if [[ " ${POSTFIX_TLS} " = " true" ]]; then
43+ echo " Configuring TLS"
44+ postconf smtp_tls_CAfile=" /etc/ssl/certs/ca-certificates.crt"
45+ postconf smtp_tls_security_level=" encrypt"
46+ postconf smtp_use_tls=" yes"
47+ fi
48+
49+ echo " Configuring SASL Auth"
50+ if [[ -n " ${POSTFIX_SASL_AUTH} " ]]; then
51+ if [[ -z " ${POSTFIX_RELAYHOST} " || -z " ${POSTFIX_TLS} " ]]; then
52+ echo " Please set 'POSTFIX_RELAYHOST' AND 'POSTFIX_TLS' before attempting to enable SSL auth."
53+ exit 1
54+ fi
55+
56+ postconf smtp_sasl_auth_enable=" yes"
57+ postconf smtp_sasl_password_maps=" hash:/etc/postfix/sasl_passwd"
58+ postconf smtp_sasl_security_options=" noanonymous"
59+ postconf smtp_tls_note_starttls_offer=" yes"
60+
61+ # generate the SASL password map
62+ echo " ${POSTFIX_RELAYHOST} ${POSTFIX_SASL_AUTH} " > /etc/postfix/sasl_passwd
63+
64+ # generate a .db file and clean it up
65+ postmap hash:/etc/postfix/sasl_passwd && rm /etc/postfix/sasl_passwd
66+
67+ # set permissions
68+ chmod 600 /etc/postfix/sasl_passwd.db
69+ fi
70+
71+
4172echo " Starting postfix in the foreground"
4273postfix start-fg
0 commit comments