Let's say you have an Ubuntu server and want to send email from the server for notification purposes AND you want the email to go to your inbox and not end up in the spam folder. Here's what you need to do.
First, install mailutils and libsasl2-modules. The libsasl2-modules package is necessary for authentication to Google's mail servers.
apt-get install mailutils libsasl2-modulesNow, we'll need a text file containing the user login for the Google account which we'll be using to access the Google relays. If it doesn't already exist, create a folder called 'sasl' in the /etc/postfix directory.
mkdir /etc/postfix/saslThen, within the sasl folder, create a file called 'sasl_passwd' or whatever you want to call it.
nano /etc/postfix/sasl/sasl_passwdWithin the sasl_passwd file, enter the following line.
[smtp.gmail.com]:587 username@gmail.com:passwordWe need to create a hash db file for postfix.
postmap /etc/postfix/sasl/sasl_passwdNext, edit postfix's main.cf file and add the following lines:
# Enable SASL authenticationsmtp_sasl_auth_enable = yes# Disallow methods that allow anonymous authenticationsmtp_sasl_security_options = noanonymous# Location of sasl_passwdsmtp_sasl_password_maps = hash:/etc/postfix/sasl/sasl_passwd# Enable STARTTLS encryptionsmtp_tls_security_level = encrypt# Location of CA certificatessmtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crtEdit the following line in main.cf to look like this:
relayhost = [smtp.gmail.com]:587Finally, restart postfix.
systemctl restart postfixIn some cases, Google won't relay. Try allowing Less Secure Apps to fix this.