• Email Address: forum@outsourcepath.com
English
  • English

Configuring Postfix to Use Gmail as SMTP server on Ubuntu 18.04


Gmail is a free email service developed by Google. Users can access Gmail on the web and using third-party programs that synchronize email content through POP or IMAP protocols.

Here at Outsource Path, we regularly help our Customers to configure SMTP Server to enable them send newsletter to their clients.
In this context, we shall look into the steps to configure postfix to use gmail as smtp server on Ubuntu 18.04.

How to Set up Postfix to Use Gmail as SMTP server on Ubuntu 18.04 ?

Follow the steps below;

1. Install postfix & mailutils
To do this, execute the command;

sudo apt-get install postfix mailutils -y

2. Postfix set up
Once installed the postfix menu will pop up. Select internet site . Leave the system mail name as default, we'll update this later.

3. Create a sasl password file
To do this, execute;

sudo vi /etc/postfix/sasl_passwd and add the following [smtp.gmail.com]:587 username@gmail.com:password

This will be the username and password for the gmail email you are using. Dont worry we'll encrypt that file later.

4. Change permission of sasl_passwd
To do this, execute;

sudo chmod 600 /etc/postfix/sasl_passwd To confirm the permission change ls -l /etc/postfix/sasl_passwd

5. Configure the postfix service
To do this, run the command;

cd /etc/postfix/ sudo vi main.cf

And add:

On line 40 add the gmail relay host relayhost = [smtp.gmail.com]:587
Than at the bottom of the file add 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.crt

6. Encrypt our sasl_passwd file
Run the command;

sudo postmap sasl_passwd

7. Tell the system where to send emails
To do this, execute;

sudo vim /etc/aliases

Postmaster should already be set up for root, if not add it. your file should look this:
postmaster: root admin: root ubuntu: root root: username@gmail.com


8. Now reload the alias database

sudo newaliases


9. Add rule to the firewall

sudo ufw allow 587


10. Restart the postfix service
Execute the command;

sudo systemctl restart postfix


11. Now lets test it
To test, run;

echo Postfix email | mail -s Email from `hostname` root

If you check your gmail account you should have a new email from your server.

Now it should be working fine.
Note: You may need to enable less secure apps for gmail.

[Need urgent support in configuring SMTP Server on your Linux Server? We are available to help you.]


Conclusion

This article will guide you on the step by step process you need to follow to Set up #postfix to use #gmail as #smtp server on #Ubuntu 18.04

Recent Post