Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


gmail_as_a_relay_on_linux

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:

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/main.cf

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

# sets gmail as relay
relayhost = [smtp.gmail.com]:587

# use tls
smtp_use_tls=yes

# 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
debug_peer_list=smtp.gmail.com
debug_peer_level=3

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

[smtp.gmail.com]: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

or

# /etc/init.d/postfix reload

or

# 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: 2018/01/27 16:16 by juckins