Configure Postfix to use Gmail
Install necessary packages first
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
Configure Postfix using
sudo dpkg-reconfigure postfix
Navigate to Postfix Directory
cd /etc/postfix
Open Postfix config file using following command
sudo gedit main.cf
Add following lines to it
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
Now we need to create a file called sasl_passwd
sudo vi /etc/postfix/sasl_passwd
Add the following line to the same
[smtp.gmail.com]:587 USERNAME@gmail.com:PASSWORD
Configure permissions for sasl_passwd
sudo chmod 400 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
Validate Certificates
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Reload Postfix
sudo /etc/init.d/postfix reload
Test Mail from Terminal
echo "Test mail from postfix" | mail -s "Test Postfix" you@example.com
Copy of my php.ini mail section
SMTP = ssl://smtp.gmail.com
smtp_port = 587
auth_username = usrname
auth_password = pwd
sendmail_from = from_mail