Christopher Juckins

SysAdmin Tips, Tricks and other Software Tools

User Tools

Site Tools


gmail_as_a_relay_on_linux

This is an old revision of the document!


Using Gmail as a Relay on Linux

Verified platforms:

  • CentOS7 7.1.1503 (Core)
  • CentOS6 6.7 (Final)

Directions based on this page by Matthew Hawthorne:

1. If installed, make sure /etc/ssmtp/ssmtp.conf is the distro version (no changes)

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:

# /etc/init.d/postfix reload

or

# service postfix restart

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

#set from = $USER@$HOSTNAME
#set from = username@HOSTNAME_OR_ALIAS.domain
#set realname="juckins@lightning"
set realname=$USER@$HOSTNAME

10. Send a test message:

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

or

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.1446691442.txt.gz · Last modified: 2015/11/04 21:44 by juckins