1. Install the needed packages
apt update
apt install -y libsasl2-modules mailutils
  1. Create app password for your google account

    • Go to App Passwords
    • Select app: Mail
    • Select device: Other
    • Type in: Proxmox or whatever you want here
  2. Write gmail credentials to file and hash it.

echo "smtp.gmail.com youremail@gmail.com:yourpassword" > /etc/postfix/sasl_passwd
 
# chmod u=rw
chmod 600 /etc/postfix/sasl_passwd
 
# generate /etc/postfix/sasl_passwd.db
postmap hash:/etc/postfix/sasl_passwd
  1. Open the postfix configuration
nano /etc/postfix/main.cf
  1. Append the following to the end of the file
relayhost = smtp.gmail.com:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
smtp_tls_session_cache_timeout = 3600s

IMPORTANT: Comment out the existing line containing just relayhost= since we are using this key in our configuration we just pasted in.

  1. Reload postfix
postfix reload
  1. Test to make sure everything works.
echo "test" | mail -s "example subject" youremail@gmail.com