Using Gmail SMTP Servers to Send Email From WordPress on DigitalOcean

Use Gmail SMTP Servers for Sending Emails from WordPress

After quite a bit of back and forth between sendmail, postfix, and exim, I’ve settled on using msmtp for sending emails from my servers/droplets at DigitalOcean (affiliate link).

MSMTP is very lightweight and has the ability to send emails via an existing SMTP server, like Gmail’s or Yahoo’s.

To get it working, there’s a few tricks. I’ve pieced this together from this post and this post. And when on DigitalOcean, there’s an IPv6 issue that causes major delays in sending the email, which there’s a fix for at the end of this post.

1. Install msmtp

sudo apt-get install msmtp

2. Configure msmtp to use Gmail

Open up /etc/msmtprc as root: sudo nano /etc/msmtprc, and add the following, removing whatever else is there:

You’ll want to replace the user directive with a valid Gmail email address, a Gmail account or a Google Apps email address will work, too. Don’t forget to change enter-password-here! to the actual password for the Gmail account your using.

Save /etc/msmtprc.

3. Remove Sendmail

Run this:

sudo apt-get remove sendmail-bin

4. Setup Some Aliases

Lots of software on Linux systems uses the sendmail command. Instead, we’re using msmtp, so we’re essentially invoking msmtp when the sendmail command is run.

6. Disable IPv6 If You Experience Slowness

Open up /etc/gai.conf like so:

sudo nano /etc/gai.conf

Now, look for a line that looks like this: #precedence ::ffff:0:0/96 100. Uncomment that line (remove the #) and save /etc/gai.conf. An explanation of why this helps can be found in this comment at the DigitalOcean article.

All Done

That should be it. If you run into any issues please do leave a comment, I’ll do my best to help you out. I may have missed a part, so no guarantees this will work for you. It does however work wonderfully on a DigitalOcean droplet that’s running Ubuntu 14.04 with a pretty standard LAMP stack.