entrypoint.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. MAIL_HOSTNAME="${MAIL_HOSTNAME:-mailhub.local}"
  4. MAIL_ORIGIN_DOMAIN="${MAIL_ORIGIN_DOMAIN:-${MAIL_HOSTNAME#*.}}"
  5. POSTFIX_LOG_FILE="${POSTFIX_LOG_FILE:-/dev/stdout}"
  6. POSTFIX_PROXY_INTERFACES="${POSTFIX_PROXY_INTERFACES:-${SENDING_IP:-}}"
  7. POSTFIX_MYHOSTNAME="${POSTFIX_MYHOSTNAME:-postfix.${MAIL_HOSTNAME}}"
  8. if [[ "${POSTFIX_LOG_FILE}" != "/dev/stdout" ]]; then
  9. mkdir -p "$(dirname "${POSTFIX_LOG_FILE}")"
  10. touch "${POSTFIX_LOG_FILE}"
  11. chmod 666 "${POSTFIX_LOG_FILE}"
  12. tail -n 0 -F "${POSTFIX_LOG_FILE}" &
  13. fi
  14. postconf -e "myhostname = ${POSTFIX_MYHOSTNAME}"
  15. postconf -e "myorigin = ${MAIL_ORIGIN_DOMAIN}"
  16. postconf -e "mydestination ="
  17. postconf -e "inet_interfaces = all"
  18. postconf -e "inet_protocols = ipv4"
  19. if [[ -n "${POSTFIX_PROXY_INTERFACES}" ]]; then
  20. postconf -e "proxy_interfaces = ${POSTFIX_PROXY_INTERFACES}"
  21. fi
  22. postconf -e "mynetworks = 127.0.0.0/8 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16"
  23. postconf -e "smtpd_relay_restrictions = permit_mynetworks, reject_unauth_destination"
  24. postconf -e "smtp_tls_security_level = may"
  25. postconf -e "smtp_tls_loglevel = 1"
  26. postconf -e "smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt"
  27. postconf -e "smtp_helo_name = ${MAIL_HOSTNAME}"
  28. postconf -e "best_mx_transport = smtp:[app]:25"
  29. postconf -e "disable_vrfy_command = yes"
  30. postconf -e "maximal_queue_lifetime = 2d"
  31. postconf -e "bounce_queue_lifetime = 2d"
  32. postconf -e "maillog_file = ${POSTFIX_LOG_FILE}"
  33. newaliases || true
  34. exec postfix start-fg