How to configure gmail server as a relayhost in Postfix?

Solution Verified - Updated -

Environment

  • Red Hat Enterprise Linux 7
  • Postfix

Issue

  • How to send mail using gmail server's authentication in Postfix?

Resolution

  • Refer following steps to configure gmail as a relay server or as a authentication server:

1) Install 'cyrus-sasl' packages on the system:

 # yum install -y cyrus-sasl-*

2) Add/change following parameters in `/etc/postfix/main.cf' file:

 relayhost = [smtp.gmail.com]:587
 smtp_use_tls = yes
 smtp_sasl_auth_enable = yes
 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 smtp_sasl_security_options = noanonymous
 smtp_sasl_tls_security_options = noanonymous

2) Add gmail's username and password in /etc/postfix/sasl_passwd file:

 [smtp.gmail.com]:587    <user>@gmail.com:<password>

3) Google requires TLS in postfix's SMTP client so add tls_policy in `/etc/postfix/main.cf' file:

 smtp_tls_policy_maps = hash:/etc/postfix/tls_policy

4) Configure encryption in /etc/postfix/tls_policy file:

 [smtp.gmail.com]:587 encrypt

5) Create the database of files:

 # chmod 600 /etc/postfix/sasl_passwd
 # postmap /etc/postfix/sasl_passwd
 # postmap /etc/postfix/tls_policy

6) Restart the postfix service:

 # systemctl restart postfix

7) Send a mail to remote user and verify the status, relayhost in '/var/log/maillog' file:

 # echo mailtest | mail -s mailtest <user>@<domain.com>

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments