Configure Postfix to Use Gmail SMTP on Ubuntu

Relaying Postfix mails via smtp.gmail.com:

First, install all necessary packages:


If you do not have postfix installed before, postfix configuration wizard will ask you some questions. Just select your server as Internet Site and for FQDN use something like mail.example.com

Open Configuration File


Look for the Configuration and change the line as below


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:


[smtp.gmail.com]:587 [email protected]:password


Fix permission and update postfix config to use sasl_passwd file:

Next, validate certificates to avoid running into error. Just run following command:

Finally, reload postfix config for changes to take effect:

Now sent the Email to test

Check if mails are sent via Gmail SMTP server

If you have configured everything correctly, the following command should generate a test mail from your server to your mailbox.


Thank You. Please dont’ forget to comment.

Leave a Comment