How to configure Postfix to send mail via Google Apps

In this tutorial, we’ll configure Postfix to send an email through Google’s SMTP on Ubuntu 12.04 LTS Server for Google Apps. We can use the exact same setup for Gmail account also:


Install Postfix and command line mail utility using the following command:

sudo apt-get install postfix mailutils


Backup the default configuration file for postfix:

sudo cp /etc/postfix/ /etc/postfix/


Edit the /etc/postfix/ file:

sudo nano /etc/postfix/


Delete everything from file and add this:

smtp_sasl_security_options = noanonymous
relayhost = []:587
smtp_use_tls = yes
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/googleapps/password


Create a directory googleapps under /etc/postfix:

sudo mkdir /etc/postfix/googleapps


Move to the /etc/postfix/googleapps directory:

cd /etc/postfix/googleapps/


Create a file named password inside /etc/postfix/googleapps directory:

sudo nano password


Add the following contents to the password file:



Note: is a Google apps mail address of mine with false password, you can use your original Google apps email address and password here.

Change the permission on password file:

sudo chmod 600 password


Transform the password file into a hashed table:

sudo postmap password


Copy CA root certificates to postfix directory:

sudo cp /etc/ssl/certs/ca-certificates.crt /etc/postfix/cacert.pem


Restart the postfix service:

sudo /etc/init.d/postfix restart


Test the postfix server by sending an email to another account:

echo "Testing" | mail -s "Email from tendo"


Check the destination email account:


Hope this will help you!

Please Remember me in your prayers!

Enjoy :-)

2 responses to “How to configure Postfix to send mail via Google Apps

  1. Pingback: CentOS :: How to setup postfix relay to Gmail / Google Apps | :: b l a c k o n s o l e ::

  2. Jason August 18, 2013 at 10:52 pm

    Thankyou for a dead simple and easy how-to on this. Many of the postfix setup how-to’s are impossible to understand, yours was dead simple and works perfectly!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: