Table of Contents

Relay to external SMTP server

Configure Postfix to Send Mail Using an External SMTP Server

Simple postfix configuration script

apt-get install postfix bsd-mailx
wget https://raw.githubusercontent.com/Tontonjo/proxmox_toolbox/main/proxmox_toolbox.sh
bash proxmox_toolbox.sh

For TLS on port 465 add followin config lines:

postconf smtp_tls_wrappermode = yes
postconf smtp_tls_security_level = encrypt

Manual configuration

# Specify zero or more "type:name" lookup tables. Type is a service defined in master.cf
cloudservice@example.org    [smtp.gmail.com]:587

cd /etc/postfix && postmap relay_by_sender

/etc/postfix/sasl_passwd
[smtp.gmail.com]:587  myrealsender@gmail.com:secret_password
cd /etc/postfix && postmap sasl_passwd
sudo chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
main.cf
...
# A sender-dependent override for the global relayhost parameter setting
sender_dependent_relayhost_maps = hash:/etc/postfix/relay_by_sender
smtp_sender_dependent_authentication = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
service postfix restart

Test email:

cat /etc/issue | mailx -r "cloudservice@example.org" -s "test relaya" "destination@email.org"

Issues

(SASL authentication failed; cannot authenticate to server smtp.server.org[11.22.33.44]: no mechanism available) solution: smtp_sasl_security_options = noanonymous