Postfix: Gmail as Relay – Linux Mint/Ubuntu/Debian

Many ISPs block sending email over port 25. This means that you won’t be able to send mail directly from your Linux server.

A good way to get around this limitation is to set up a relay through a Gmail account.

1. Install the Required Packages

Execute the following command to install required packages:

$ sudo apt-get install mailutils

During the installation, a popup box may display. If it does, select your server as Internet Site and for FQDN use something like domain.tld

2. Configure Postfix to use Gmail as Relay

Edit the Postfix configuration file:

$ sudo vi /etc/postfix/

Add the following lines:

# Relaying Postfix SMTP via GMAIL
relayhost = []:587
smtp_sasl_auth_enable = yes
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

3. Setup Gmail Credentials

Open (create) the file sasl_passwd:

$ sudo vi /etc/postfix/sasl_passwd

Add the following line (set your Gmail username and password):


Set the permissions and tell Postfix to use the sasl_passwd file:

$ sudo chmod 400 /etc/postfix/sasl_passwd
$ sudo postmap /etc/postfix/sasl_passwd

4. Validate the Certificate

Add the certificate to Postfix, as follows:

$ cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem

5. Test Postfix with Gmail SMTP Realy

Restart Postfix to apply all changes.

$ sudo service postfix restart

Try to send an email.

$ echo "Hello World" | mail -s "Test Message"

Check the mail log:

$ tail /var/log/mail.log

If all goes well, you should not see any errors.

Once configured, all emails from your server will be sent via Gmail.

The Gmail’s SMTP Server has a limit of 500 emails per day. So use it wisely!

One Reply to “Postfix: Gmail as Relay – Linux Mint/Ubuntu/Debian”

  1. Brilliant – I’ve tried several sites, but couldn’t get the install to work.
    You’re instructions were easy to follow and worked first time
    ( except for a minor change to the certificate name – I had to use thawte_Primary_Root_CA.pem )

Leave a Reply