If you want to use a Gmail account as a free SMTP server on your Ubuntu-Linux server, you will find this article useful. This guide is tested with Ubuntu 12.04. If you face any issue, feel free to use comments-section below.
First, install all necessary packages:
sudo apt-get install postfix mailutils libsasl2-2 ca-certificates libsasl2-modules
If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site.
Then open your postfix config file:
and 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
You might have noticed that we haven’t specified our Gmail username and password in above lines. They will go into a different file. Open/Create
And add following line:
Next, validate certificates to avoid running into error. Just run following command:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
Note: If you run into issues with above command, try changing certificate name to
thawte_Primary_Root_CA.pem in above command.
Finally, reload postfix config for changes to take effect:
sudo /etc/init.d/postfix reload
Check if mails are sent via Gmail SMTP server
If you have configured everything correctly, following command should generate a test mail from your server to your mailbox.
echo "Test mail from postfix" | mail -s "Test Postfix" email@example.com