Configuring Google’s SMTP Via Smtpmail on Linode CentOS

When you install WordPress on Linode, one thing that's not supported out of box is mail - php requires sendmail installed and running.

Configurations might differ depending on the exact use case, but for my WordPress I wanted to use Google's SNMP server. While guides are plentiful, most of information is a bit obsolete - whether it is in regards to package name or exact configuration. So I went my own way...

To get us going, we need to install a few packages related to sendmail functionality and allow the same in SELinux (if enforced):

# yum install -y sendmail sendmail-cf cyrus-sasl-plain cyrus-sasl-md5
# setsebool -P httpd_can_sendmail on

First thing to prepare is file containing our authentication details for Google's server. I will assume here that login you usually use is relay@gmail.com and password is password. Of course, these must be substituted for correct values:

# mkdir -p -m 700 /etc/mail/authinfo
# echo 'AuthInfo: "U:root" "I:relay@gmail.com" "P:password"' > /etc/mail/authinfo/gmail
# makemap hash /etc/mail/authinfo/gmail < /etc/mail/authinfo/gmail

To /etc/mail/sendmail.mc we need to add the following lines just ABOVE the first MAILER line.


define(`SMART_HOST',`[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confCACERT', `/etc/pki/tls/certs/ca-bundle.trust.crt')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail.db')dnl

Once configuration has been updated, we can proceed with "compiling" that new configuration and starting the daemon for the first time.

# make -C /etc/mail
# systemctl start sendmail

The easiest test is sending an e-mail via command line:

# echo "Subject: Test via sendmail" | sendmail -v youremail@example.com

If there are issues, you can always check journal for startup errors:

# journalctl -xe

The most common error is "available mechanisms do not fulfill requirements" and that signals Cyrus SASL plugins are not installed for MD5 and PLAIN methods. Make sure cyrus-sasl-plain and cyrus-sasl-md5 packages are installed.

Lastly, if sendmail does work but it is very slow, add your hostname (output of hostname command) to the end of localhost (IPv4 and IPv6) entries in /etc/hosts file.

Leave a Reply

Your email address will not be published. Required fields are marked *