Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable SMTP relay if configured via environment variables. #2258

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions setup/mail-postfix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,24 @@ ufw_allow smtp
ufw_allow smtps
ufw_allow submission

# Configure SMTP Relay

if [[ -n "${SMTP_RELAY_ENDPOINT:-}" && -n "${SMTP_RELAY_PORT:-}" && \
-n "${SMTP_RELAY_USER:-}" && -n "${SMTP_RELAY_PASSWORD:-}" ]]; then
postconf -e "relayhost = [$SMTP_RELAY_ENDPOINT]:$SMTP_RELAY_PORT" \
"smtp_sasl_auth_enable = yes" \
"smtp_sasl_security_options = noanonymous" \
"smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd" \
"smtp_use_tls = yes" \
"smtp_tls_security_level = encrypt" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the value that we set elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested this and did not see any impact on the overall behaviour of my box other than the relaying.

Though happy to scope it down. Can you elaborate what specifically you see is conflicting?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The purpose of relayhost is to send all mail via the relay, so the settings should match the relay. It doesn´t matter anymore how we set them elsewhere. However, if we don´t want to use the relay anymore, make sure the settings are restored to their original settings.

"smtp_tls_note_starttls_offer = yes"
echo "[$SMTP_RELAY_ENDPOINT]:$SMTP_RELAY_PORT $SMTP_RELAY_USER:$SMTP_RELAY_PASSWORD" >> /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
postconf -e 'smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt'
fi

# Restart services

restart_service postfix
Expand Down