|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | + |
| 4 | +set -eo pipefail |
| 5 | + |
| 6 | +echo "Configuring postfix with any environment variables that are set" |
| 7 | + |
| 8 | +if [[ -n "${POSTFIX_MYNETWORKS}" ]]; then |
| 9 | + echo "Setting custom 'mynetworks' to '${POSTFIX_MYNETWORKS}'" |
| 10 | + postconf mynetworks="${POSTFIX_MYNETWORKS}" |
| 11 | +else |
| 12 | + echo "Set 'mynetworks' to default" |
| 13 | + postconf mynetworks="127.0.0.1/32 172.0.0.0/8" |
| 14 | +fi |
| 15 | + |
| 16 | +if [[ -n "${POSTFIX_RELAYHOST}" ]]; then |
| 17 | + echo "Setting custom 'relayhost' to '${POSTFIX_RELAYHOST}'" |
| 18 | + postconf relayhost="[${POSTFIX_RELAYHOST}]:${POSTFIX_RELAYHOST_PORT}" |
| 19 | +else |
| 20 | + echo "Set 'relayhost' to default (unset)" |
| 21 | + postconf -# relayhost |
| 22 | +fi |
| 23 | + |
| 24 | +echo "Disable chroot for the smtp service" |
| 25 | +postconf -F smtp/inet/chroot=n |
| 26 | +postconf -F smtp/unix/chroot=n |
| 27 | + |
| 28 | +if [[ "${POSTFIX_INETPROTOCOLS}" = "all" ]]; then |
| 29 | + echo "Enabling IPv4 and IPv6" |
| 30 | + postconf inet_protocols="all" |
| 31 | +elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv6" ]]; then |
| 32 | + echo "Enabling IPv6" |
| 33 | + postconf inet_protocols="ipv6" |
| 34 | +elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv4, ipv6" ]]; then |
| 35 | + echo "Enabling IPv4 and IPv6" |
| 36 | + postconf inet_protocols="all" |
| 37 | +elif [[ "${POSTFIX_INETPROTOCOLS}" = "ipv4" ]]; then |
| 38 | + echo "Enabling IPv4" |
| 39 | + postconf inet_protocols="ipv4" |
| 40 | +else |
| 41 | + echo "Enabling IPv4" |
| 42 | + postconf inet_protocols="ipv4" |
| 43 | +fi |
| 44 | + |
| 45 | +#echo "Disable ipv6" |
| 46 | +#postconf inet_protocols="ipv4" |
| 47 | + |
| 48 | +if [[ "${POSTFIX_TLS}" = "true" ]]; then |
| 49 | + echo "Configuring TLS" |
| 50 | + postconf smtp_tls_CAfile="/etc/ssl/certs/ca-certificates.crt" |
| 51 | + postconf smtp_tls_security_level="encrypt" |
| 52 | + postconf smtp_use_tls="yes" |
| 53 | + postconf smtp_tls_wrappermode="yes" |
| 54 | +fi |
| 55 | + |
| 56 | +if [[ -n "${POSTFIX_SASL_AUTH}" ]]; then |
| 57 | + echo "Configuring SASL Auth" |
| 58 | + if [[ -z "${POSTFIX_RELAYHOST}" || -z "${POSTFIX_TLS}" ]]; then |
| 59 | + echo "Please set 'POSTFIX_RELAYHOST' AND 'POSTFIX_TLS' before attempting to enable SSL auth." |
| 60 | + exit 1 |
| 61 | + fi |
| 62 | + |
| 63 | + postconf smtp_sasl_auth_enable="yes" |
| 64 | + postconf smtp_sasl_password_maps="lmdb:/etc/postfix/sasl_passwd" |
| 65 | + postconf smtp_sasl_security_options="noanonymous" |
| 66 | + postconf smtp_tls_note_starttls_offer="yes" |
| 67 | + # generate the SASL password map |
| 68 | + echo "${POSTFIX_RELAYHOST} ${POSTFIX_SASL_AUTH}" > /etc/postfix/sasl_passwd |
| 69 | + |
| 70 | + # generate a .db file and clean it up |
| 71 | + postmap lmdb:/etc/postfix/sasl_passwd && rm /etc/postfix/sasl_passwd |
| 72 | + |
| 73 | + # set permissions |
| 74 | + chmod 600 /etc/postfix/sasl_passwd.lmdb |
| 75 | +fi |
| 76 | +postconf maillog_file=/var/log/postfix.log |
| 77 | +postconf maillog_file_permissions=0644 |
| 78 | + |
| 79 | +echo "Starting postfix" |
| 80 | +postfix start-fg |
0 commit comments