Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


This is an old revision of the document!

Using Gmail as a Relay on CentOS Linux

Required packages if CentOS6 6.7:

  • postfix (tested version 2:2.6.6-6.el6_5)
  • ca-certificates.noarch (tested version 2015.2.4-65.0.1.el6_6)

Required packages if CentOS7 7.1.1503:

  • postfix (tested version 2:2.10.1-6.el7)
  • ca-certificates.noarch (tested version 2015.2.4-70.0.el7_1)

Other CentOS 7 Notes:

Directions based on this page by Matthew Hawthorne:

1. If installed, make sure /etc/ssmtp/ssmtp.conf is the distro version (no changes, and it is not needed on CentOS 7)

2. Make a backup copy of /etc/postfix/

3. Edit /etc/postfix/ to have these settings:

# sets gmail as relay
relayhost = []:587

# use tls

# use sasl when authenticating to foreign SMTP servers
smtp_sasl_auth_enable = yes 

# path to password map file
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

# list of CAs to trust when verifying server certificate
#smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
# Below is provided by ca-certificates package (Mozilla CA root certificate bundle)
smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt

# eliminates default security options which are incompatible with Gmail
smtp_sasl_security_options =

# add debugging

4. Add your own Gmail credentials to /etc/postfix/sasl_passwd

[]:587  username:password

5. Run the following as root:

# postmap /etc/postfix/sasl_passwd

6. Make sure the /etc/sasl_passwd* files are owned by the postfix user:

# chown postfix sasl_passwd*

7. Tighten permissions:

# chmod 600 sasl_passwd sasl_passwd.db

8. Restart postfix:

# /bin/systemctl restart postfix.service


# /etc/init.d/postfix reload


# service postfix restart

9. Edit ~/.muttrc for each user as appropriate:

#set from = [email protected]$HOSTNAME
#set from = [email protected]_OR_ALIAS.domain
#set [email protected]$HOSTNAME - doesn't get the hostname (?)
set realname="[email protected]"

10. Send a test message:

mutt -s "Test1" [email protected] </dev/null


echo 'It works' | mailx -s 'Test message' [email protected]

Other links:

How to send email with my CentOS server
Setting up gmail as a relay host in postfix (without creating certificates)
How To Use Gmail or Yahoo with PHP mail() Function
Updating certificates (not needed at this point)

gmail_as_a_relay_on_linux.1460596478.txt.gz · Last modified: 2016/04/13 21:14 by juckins