Send mail via Gmail from a local postfix server on Ubuntu
René Dohmen
December 16, 2014
1 min

If you want to use Gmail for sending mails from postfix follow this guide.

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 you like or if you have a FQDN; use that.

Add the following lines to /etc/postfix/main.cf

Create a new file /etc/postfix/sasl_passwd to store the Gmail credentials:

Note: If you want to use your Google App’s domain, just replace \@gmail.com with your \@yourgoogleappsdomain.com

Fix permission and update postfix config to use sasl_passwd file:

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

Restart your postfix server:

Note: you can ignore errors like: warning: /etc/postfix/main.cf, line 43: overriding earlier entry: relayhost=

Test your setup with:


If you run into troubles you probably are sending mail from a new IP of from a Gmail address that wasn’t used before.

In maillog you will find something like: Error: “SASL authentication failed; server smtp.gmail.com”

You need to unlock the captcha by visiting this page https://www.google.com/accounts/DisplayUnlockCaptcha

You can run test again after unlocking captcha.

Related Posts

Deploy FastAPI on Amazon Serverless
May 15, 2021
5 min
© 2021, All Rights Reserved.
Powered by formatics

Quick Links

Advertise with usAbout UsContact Us

Social Media