MySQL support

This commit is contained in:
James Pattinson
2025-10-12 19:24:14 +00:00
parent b54014ac76
commit 35f710049a
10 changed files with 296 additions and 9 deletions

View File

@@ -4,21 +4,22 @@ FROM debian:stable-slim
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y \
postfix \
postfix-mysql \
libsasl2-modules \
mailutils \
gettext-base \
netcat-openbsd \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Copy configs
COPY main.cf.template /etc/postfix/main.cf.template
COPY sasl_passwd.template /etc/postfix/sasl_passwd.template
COPY virtual_aliases.cf /etc/postfix/virtual_aliases.cf
COPY mysql_virtual_alias_maps.cf /etc/postfix/mysql_virtual_alias_maps.cf.template
COPY sender_access /etc/postfix/sender_access
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Generate Postfix maps for virtual aliases and sender access
RUN postmap /etc/postfix/virtual_aliases.cf
# Generate Postfix maps for sender access
RUN postmap /etc/postfix/sender_access
# Expose SMTP

View File

@@ -4,16 +4,33 @@ set -e
# Generate main.cf from template with environment variables
envsubst < /etc/postfix/main.cf.template > /etc/postfix/main.cf
# Generate MySQL virtual alias config from template
envsubst < /etc/postfix/mysql_virtual_alias_maps.cf.template > /etc/postfix/mysql_virtual_alias_maps.cf
# Generate SASL password file from environment variables
envsubst < /etc/postfix/sasl_passwd.template > /etc/postfix/sasl_passwd
# Wait for MySQL to be ready
echo "Waiting for MySQL to be ready..."
for i in $(seq 1 30); do
if nc -z ${MYSQL_HOST} ${MYSQL_PORT} 2>/dev/null; then
echo "MySQL is ready!"
break
fi
echo "Waiting for MySQL... ($i/30)"
sleep 2
done
# Generate Postfix hash databases
postmap /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
# Regenerate sender_access database (in case of updates)
# Regenerate sender_access database
postmap /etc/postfix/sender_access
chmod 644 /etc/postfix/sender_access /etc/postfix/sender_access.db
# Set permissions on MySQL config
chmod 644 /etc/postfix/mysql_virtual_alias_maps.cf
# Start Postfix in foreground
exec postfix start-fg

View File

@@ -16,8 +16,8 @@ smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
# Virtual aliases (static for now)
virtual_alias_maps = hash:/etc/postfix/virtual_aliases.cf
# Virtual aliases - dynamic MySQL lookup
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
# Sender restrictions - enforce whitelist
smtpd_sender_restrictions =

View File

@@ -0,0 +1,14 @@
# Postfix MySQL query for virtual aliases
# This file queries the database to expand mailing list addresses to member emails
# Database connection settings
hosts = ${MYSQL_HOST}
port = ${MYSQL_PORT}
user = ${MYSQL_USER}
password = ${MYSQL_PASSWORD}
dbname = ${MYSQL_DATABASE}
# Query to get recipients for a mailing list
# Input: full email address (e.g., community@lists.sasalliance.org)
# Output: comma-separated list of recipient emails
query = SELECT GROUP_CONCAT(m.email SEPARATOR ', ') FROM lists l INNER JOIN list_members lm ON l.list_id = lm.list_id INNER JOIN members m ON lm.member_id = m.member_id WHERE l.list_email = '%s' AND l.active = 1 AND m.active = 1 AND lm.active = 1 GROUP BY l.list_id

View File

@@ -1 +1,11 @@
community@lists.sasalliance.org james@pattinson.org, james.pattinson@sasalliance.org
# Community mailing list - general announcements
community@lists.sasalliance.org james@pattinson.org, james.pattinson@sasalliance.org
# Board members mailing list
board@lists.sasalliance.org james.pattinson@sasalliance.org
# All members mailing list
members@lists.sasalliance.org james@pattinson.org, james.pattinson@sasalliance.org
# Announcements mailing list
announcements@lists.sasalliance.org james@pattinson.org, james.pattinson@sasalliance.org