Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


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.2.1511:

  • postfix (tested version 2.10.1-6.el7 )
  • ca-certificates.noarch (tested version 2015.2.4-70.0.el7_1)
  • cyrus-sasl-plain (tested version 2015.2.6-70.1.el7_2)
  • cyrus-sasl-lib (tested version 2.1.26-20.el7_2)

Other CentOS 7 Notes:

  • Best to use this version of mutt: mutt-1.6.2-1.fc22.x86_64.rpm
    • Otherwise, you may get errors like: Bad IDN in “from”: 'tidewater.�'
  • /etc/resolv.conf may need the 'search' pattern, ex: search
    • As root, run 'nmtui' to set network parameters
  • If trouble sending after install, may need to consult this link

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 realname="[email protected]"
set realname="[email protected]$HOSTNAME" (works in CENTOS7, mutt-1.5.21-26.el7.x86_64 but *not* via cron sending)

10. Send a test message:

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

or to send a message without using a separate file:

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.txt · Last modified: 2019/05/01 11:25 by juckins