Ubuntu Linux, ubuntu desktop, Linux operating system, ubuntu guide

Set Up Postfix For Relaying Emails via gmail smtp server

by on Jun.07, 2012, under Ubuntu

This short guide shows how you can set up Postfix to relay emails through another mailserver. This can be useful if you run a Postfix mailserver in your local network.

There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you.

Relay Mail

An open mail relay is an SMTP server configured in such a way that it allows anyone on the Internet to send e-mail through it, not just mail destined to or originating from known users.

To configure relaying on your Postfix mailserver, you need a valid email account in gmail (with username and password) use of SMTP-AUTH .

Gmail smtp server is ” gmail-smtp-in.l.google.com “ .

Installed the postfix package and uncomment myhostname, my domain,myorgin and inet_interfaces = all.

Set your hostname FQDN format.

Relay Setup in Postfix

To configure our Postfix server for relaying emails through  gmail-smtp-in.l.google.com, we run

postconf -e ‘relayhost = gmail-smtp-in.l.google.com’
postconf -e ‘smtp_sasl_auth_enable = yes’
postconf -e ‘smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd’
postconf -e ‘smtp_sasl_security_options =’

Our username (sahabcse@gmail.com) and password (XXXXXX) for  gmail-smtp-in.l.google.com must be stored in /etc/postfix/sasl_passwd, therefore we do this

echo “gmail-smtp-in.l.google.com   sahabcse@gmail.com:XXXXXX” > /etc/postfix/sasl_passwd

/etc/postfix/sasl_passwd must be owned by root, and noone else should have read access to that file, so we do this:

chown root:root /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd

Now we must convert /etc/postfix/sasl_passwd into a format that Postfix can read:

postmap /etc/postfix/sasl_passwd

This will create the file /etc/postfix/sasl_passwd.db.

All that is left to do is restart Postfix:

/etc/init.d/postfix restart

That’s it. You can now test by sending emails over your mailserver and having a look at your mail log. You should see that all your emails are now passed on to gmail-smtp-in.l.google.com(except the ones that have a local recipient.

#mail sahabcse@gmail.com
Subject: HII
Null message body; hope that’s ok

#tail -f /var/log/maillog

postfix/smtp[9371]: 350BD10E0049: to=<sahabcse@gmail.com>, relay=gmail-smtp-in.l.google.com[]:25, delay=2, delays=0.07/0/0.78/1.1, dsn=2.0.0, status=sent (250 2.0.0 OK 1338992471 ve2si757562pbc.294)


2 Comments for this entry

  • brett

    When I follow your steps, my maillog has the following:

    Sep 19 15:13:01 project postfix/smtp[31894]: connect to gmail-smtp-in.l.google.com[2607:f8b0:400e:c03::1a]:25: Network is unreachable
    Sep 19 15:13:22 project postfix/smtp[31894]: connect to gmail-smtp-in.l.google.com[]:25: Connection timed out
    Sep 19 15:13:22 project postfix/smtp[31894]: 97DF2A03B1: to=, relay=none, delay=22, delays=0.03/0.07/21/0, dsn=4.4.1, status=deferred (connect to gmail-smtp-in.l.google.com[]:25: Connection timed out)

    Any ideas?

  • Ignacio Gomez

    unused parameter: smtp_sasl-passwords-maps= /etc/postfix/sasl_password why? it doesn´t work happens when restarting the service. plese help

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!