Edit

Configure Postfix to use Gmail SMTP as Mail Relay

Note:
OS: Ubuntu

$ apt update && apt install postfix mailutils
$ cat /etc/postfix/sasl_passwd
[smtp.gmail.com]:587 username@gmail.com:password
$ chmod 600 /etc/postfix/sasl_passwd
$ cat /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
$ postmap /etc/postfix/sasl_passwd
$ rm /etc/postfix/sasl_passwd
$ cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
or
$ cat /etc/ssl/certs/thawte_Primary_Root_CA.pem | sudo tee -a /etc/postfix/cacert.pem
$ systemctl restart postfix.service (service postfix restart/reload/start/stop)
$ /etc/init.d/postfix reload
$ mail -s "Test subject" recipient@domain.com
$ mail -s "Subject Here" recipient@domain.com < textfile
$ echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com
$ tail -100f /var/log/mail.log
$ journalctl

%23%23%23%60Configure%20Postfix%20to%20use%20Gmail%20SMTP%20as%20Mail%20Relay%60%0A%0A%3E**Note%3A**%0A*OS%3A%20Ubuntu*%0A%60%60%60sh%0A%24%20apt%20update%20%26%26%20apt%20install%20postfix%20mailutils%0A%24%20cat%20/etc/postfix/sasl_passwd%0A%20%20%5Bsmtp.gmail.com%5D%3A587%20%20%20%20username@gmail.com%3Apassword%0A%24%20chmod%20600%20/etc/postfix/sasl_passwd%0A%24%20cat%20/etc/postfix/main.cf%0A%20%20relayhost%20%3D%20%5Bsmtp.gmail.com%5D%3A587%0A%20%20smtp_sasl_auth_enable%20%3D%20yes%0A%20%20smtp_sasl_password_maps%20%3D%20hash%3A/etc/postfix/sasl_passwd%0A%20%20smtp_sasl_security_options%20%3D%20noanonymous%0A%20%20smtp_tls_CAfile%20%3D%20/etc/postfix/cacert.pem%0A%20%20smtp_use_tls%20%3D%20yes%0A%24%20postmap%20/etc/postfix/sasl_passwd%0A%24%20rm%20/etc/postfix/sasl_passwd%0A%24%20cat%20/etc/ssl/certs/Thawte_Premium_Server_CA.pem%20%7C%20sudo%20tee%20-a%20/etc/postfix/cacert.pem%0A%20%20or%0A%24%20cat%20/etc/ssl/certs/thawte_Primary_Root_CA.pem%20%7C%20sudo%20tee%20-a%20/etc/postfix/cacert.pem%20%20%0A%24%20systemctl%20restart%20postfix.service%20%28service%20postfix%20restart/reload/start/stop%29%0A%24%20/etc/init.d/postfix%20reload%0A%24%20mail%20-s%20%22Test%20subject%22%20recipient@domain.com%0A%24%20mail%20-s%20%22Subject%20Here%22%20recipient@domain.com%20%3C%20textfile%0A%24%20echo%20%22Test%20mail%20from%20postfix%22%20%7C%20mail%20-s%20%22Test%20Postfix%22%20you@example.com%0A%24%20tail%20-100f%20/var/log/mail.log%0A%24%20journalctl%0A%0A%60%60%60%0A%0A%0A@%28Postach.io%29%5Bpostfix%2Cmail%2Csmtp%2Cgmail%2Crelay%2Cpublished%5D