sudo apt-get update && sudo apt-get install postfix mailutils2. Configure Gmail Authentication Create or modify a password file which will be used by Postfix to establish authentication with Gmail. In the authentication information below, replace username with your Gmail username and password with your Gmail password. If you are using a custom Gmail Apps domain name, you may replace gmail.com with your Google Apps domain. The password file will reside in the Postfix configuration directory. The file can be named whatever you like, but the recommended filename is sasl_passwd. a. Open file for edit:
vi /etc/postfix/sasl_passwdb. Add the following line to above file:
[smtp.gmail.com]:587 email@example.com:passwordc. And then make sure that the file is only readable by yourself:
chmod 600 /etc/postfix/sasl_passwd3. Configure Postfix Now, we need to configure Postfix by adding the following lines to its main configuration file. Open /etc/postfix/main.cf using your favourite editor and then add below content:
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/ca-certificates.crt4. Process Password File Use postmap to compile and hash the contents of sasl_passwd. The results will be stored in your Postfix configuration directory in the file sasl_passwd.db.
postmap /etc/postfix/sasl_passwd5. Restart Postfix server, so that the configurations will take effect:
sudo systemctl restart postfix.service6. Lastly, we need to Enable “Less Secure Apps” In Gmail By default, only the most secure sign-ins, such as logging in to Gmail on the web, are allowed for your Gmail account. To permit relay requests, log in to your Gmail account and turn on Allow less secure apps (you will need to login first before you can turn on the setting). For more information, please refer to “Allowing less secure apps to access your account.” 7. To confirm everything is working, run below command to test:
mail -s "Test subject" firstname.lastname@example.orgIf no emails, check log file under /var/log/mail.log to see what message reported from Postfix and fix accordingly. Hope this can also help with anyone who lands on my blog.