feat(postfix-pgsql): add Dockerfile with templated config and entrypoint

This commit is contained in:
Damien
2026-06-25 11:12:46 +02:00
parent 1af298f74e
commit 8143fff65f
5 changed files with 166 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
# =============================================================================
# Postfix main.cf template
#
# Rendered at container startup by docker-entrypoint.sh, with values
# substituted from environment variables. See README.md for the full list
# of supported variables.
# =============================================================================
myhostname = ${MYHOSTNAME}
mydomain = ${MAIL_DOMAIN}
myorigin = $mydomain
mydestination =
inet_interfaces = all
inet_protocols = ipv4
# Dynamic relay/transport decisions backed by PostgreSQL lookup maps.
relay_domains = pgsql:/etc/postfix/pgsql-relay-domains.cf
transport_maps = pgsql:/etc/postfix/pgsql-transport-maps.cf
# This instance only relays mail for the domains returned by relay_domains;
# it does not accept mail for arbitrary destinations.
smtpd_relay_restrictions = permit_mynetworks, reject_unauth_destination
mynetworks = 127.0.0.0/8, [::1]/128
# TLS
smtpd_tls_cert_file = ${SMTPD_TLS_CERT_FILE}
smtpd_tls_key_file = ${SMTPD_TLS_KEY_FILE}
smtpd_use_tls = yes
smtpd_tls_security_level = may
smtp_tls_security_level = may
# Log to stdout/stderr so `docker logs` captures Postfix activity directly,
# without needing a syslog daemon inside the container.
maillog_file = /dev/stdout
biff = no
append_dot_mydomain = no
readme_directory = no
compatibility_level = 3.6

View File

@@ -0,0 +1,12 @@
# =============================================================================
# Postfix pgsql_table lookup: relay_domains
#
# Returns the domain itself when Postfix should relay mail for it.
# Rendered at container startup from environment variables.
# =============================================================================
user = ${POSTGRES_USER}
password = ${POSTGRES_PASSWORD}
hosts = ${POSTGRES_HOST}:${POSTGRES_PORT}
dbname = ${POSTGRES_DB}
query = SELECT domain FROM relay_domain WHERE domain='%s'

View File

@@ -0,0 +1,15 @@
# =============================================================================
# Postfix pgsql_table lookup: transport_maps
#
# Returns the internal SMTP relay target that accepted mail gets forwarded
# to once a recipient domain matches relay_domains. The target itself is
# baked into the query from SMTP_RELAY_HOST/SMTP_RELAY_PORT at startup; this
# image has no further knowledge of what consumes the mail downstream.
# Rendered at container startup from environment variables.
# =============================================================================
user = ${POSTGRES_USER}
password = ${POSTGRES_PASSWORD}
hosts = ${POSTGRES_HOST}:${POSTGRES_PORT}
dbname = ${POSTGRES_DB}
query = SELECT 'smtp:[${SMTP_RELAY_HOST}]:${SMTP_RELAY_PORT}' FROM relay_domain WHERE domain='%s'