How to Configure Postfix GMAIL SMTP Server on Your Ubuntu Server
If you want to use external SMTP server as your primary e-mail server, it is recommended to use the most popular e-mail service – Gmail – for this purpose. Gmail allows you to use its SMTP server as relay. This tutorial will explain how to configure Postfix to use Gmail as e-mail relay on Ubuntu 14.04 operating system.
First, update your operating system and install nano text editor:
sudo apt-get install nano
<>Now you will have to install Postfix and required packages (mail utilities, ca certificates):
In most cases (especially if you are using OpenVZ template), Postfix will be installed on your operating system template by default. However, you will be asked some questions if it is not installed. You have to select Internet Site as server and type fully qualified domain name (FQDN) as your e-mail server, for example: mail.example.com.
Now if your installation passed without any issues or errors, you have to edit Postfix configuration file, which is located in
sudo nano /etc/postfic/main.cf
Add [smtp.gmail.com]:587 as your relay host:
Add the following lines to the configuration file:
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 have not specified your gmail credentials yet, so now you have to create file where your gmail login credentials will be stored:
Open newly created file with nano text editor:
Add the following line:
Fix file permissions and update Postfix configuration to use sasl_passwd file:
sudo postmap /etc/postfix/sasl_passwd
Next – validate your certificate in order to avoid any possible errors:
Finally, reload Postfix configuration for the changes to take effect:
Your server is prepared to use Gmail service as your main SMTP service, try if it is working:
Gmail will refuse your connection by default due to security restrictions. Log in to your gmail account, where you will see a security notification about unauthorized access from unsecured server. Verify that you have issued this login and change security settings. You must visit the following link in order to do that:
And turn on unsecured software access.
Try to send the test e-mail once again – it should be sent without any issues. You may check your sent messages folder – all sent messages will be stored there.
NOTE: Do not forget that Gmail has a restriction of 500 e-mails per day.
TIP: Try to telnet smtp.gmail.com via 587 port if you are experiencing any issues. Contact your server administrator if you are unable to telnet it. Otherwise, it means that you have made a mistake during the configuration.