If you’ve spent any amount of time with WordPress, the chances are that you’ve experienced some sort of problem with emails. One of the most common functions in WordPress is wp_mail(), which allows WordPress core as well as plugins to send emails from the site to necessary parties. That could be new user accounts, password resets, event reminders or order confirmations.
In certain situations, the importance of these emails can be quite high. For example, if an online store fails to issue an email receipt, that could be a big problem. Worse yet, if the order is a digital product which is delivered by email, that problem gets even bigger.
Unfortunately, wp_mail() is not the most reliable way to send emails. It uses PHPMailer to send emails, which uses a PHP process on the server on which your WordPress install resides. This has many pitfalls:
- If your site gets overloaded, PHP functions can time out. When they do, there’s no queue for emails to go out, so the email doesn’t get sent and no one gets notified.
- If you’re on a shared hosting environment, you’re sending email from the IP address of your shared server. Someone else on that server, either currently or historically, may have been abusing those server resources and resulted in the IP address getting blacklisted, which can cause your emails to automatically get marked as spam.
- There is no verification: your server sends emails claiming to be from your domain, but there’s no proof of that, so it’s hard for email services to take that at face value. Using PHPMailer, you can send emails claiming to be from any email address. Note that you never have to give WordPress login credentials for your email accounts, because it doesn’t prove that it’s from your email address: it just claims to be.
But there’s ways to get around this. The next, simple step, is to route your emails through an SMTP server, like your GMail account, using a plugin like Easy WP SMTP. In this scenario, you give WordPress your GMail login and WordPress sends emails directly through that account, as if you had signed into GMail, composed the email and sent it yourself.
This is better, but it still has some pitfalls, so if you find yourself at this juncture, you may as well go another step and use a third-party email service instead.
The next step is to offload all of your email sending to a third-party service. There are a few players in this arena, but the two biggest are Amazon SES and Mandrill. Mandrill has the advantage of being owned by MailChimp, so if you already have some MailChimp lists, it may be worth looking into. However, it is also much more expensive. At the time of writing, Amazon SES charges $0.10 per 1,000 emails; Mandrill charges $20 per 25,000 emails (equating to $0.80 per 1,000 emails). As such, Mandrill is 8 times as expensive and your credits expire each month, whereas Amazon SES is very much pay-as-you-go, so if you only send 100 emails in a month, you only pay a penny.
As you can see, Amazon SES is extremely affordable. Even for a good-sized site, where you’re sending up to 10,000 emails a month, Amazon SES will only cost you $1, so you can seethat cost really isn’t a berrier to getting started with SES.
Configuring Amazon SES
To set up Amazon SES, you need access to your domain’s DNS records. This is how Amazon is able to verify that you own the domain and that you have the authority to send from it. This is one aspect of how your email becomes much more trusted. Furthermore, it allows you to set up DKIM records, which is a secure way of the people receiving your emails being able to confirm that the email came from the owner of the domain. This combination of factors is how your email can become much more reliable and much less likely to show up in spam folders.
To get started, sign up for an Amazon Web Services account. If you already have an Amazon account, you can use that to sign in with. After that, if you head to your console and select the SES service, you’ll see where you can add new domains.
The process of verifying a new domain involves generating the DNS records for Amazon SES. You should select to Generate DKIM Settings as well. This will give you a list of of DNS records that you need add at your domain registrar. Unless you want to receive email at Amazon SES (which is unnecessary in most cases), you can ignore the MX record it gives you (meaning that you’ll only add the CNAME and TXT records that you’re provided).
Once you configure your DNS records, click on close. The process of verifying your domain can be as quick as immediate, or it might take a few hours. Either way, you’ll receive an email once your domain has been verified.
Next, you need to verify an email account which you want to send emails from. You can do this by selecting “Email Addresses” from the sidebar and clicking on “Verify a New Email Address”, which will send you an email at the email address you specified and ask you to click on a link to take you back to your Amazon SES account.
The next step is to create an IAM User, which is like an API key, enabling you to connect your Amazon SES account to your WordPress installation. Go to My Account > My Security Credentials > Users > Add User. Set the user to have “Programmatic Access” and under Permissions, choose “Attach Existing Policies Directly” and then choose AmazonSESFullAccess. When you create the user, you’ll be given an access key ID and a secret access key. Copy those down and keep them for later.
Once you get to this point, your email account and domain have been verified, your DKIM records are in place and you’ve set up access to Amazon SES. The next step is to request a sending limit increase from Amazon. This process lets Amazon know what you intend to use SES for and gives them an idea of how many emails you might be sending. For example, I sent a request to send up to 100 emails per day (which is well in excess of what I truly need) and they gave me a limit of 50,000 emails per day. To request this increase, go to Sending Statistics in the sidebar and then choose Request Increased Sending Limits. It can take up to 24 hours for your request to be reviewed and approved.
Once your sending limit request has been approved, you’re now ready to start using Amazon SES.
Setting up WordPress for Amazon SES
The process of adding Amazon SES to WordPress is pretty painless. Start off by installing and activating WP SES. From there, go to the Settings page, under Settings > WP SES from the left menu. Fill out the details on this page, using the email address that you already verified, and the access key and secret key from your IAM user.
You should now see a message at the top of the screen saying that your credentials were accepted, but that the plugin is not yet activated (if it doesn’t show that the API keys are valid, try using the Refresh button). This is a good time to test the setup. You can use the Test Email section whether or not your AWS account is in production mode yet or not (whether your sending limit increase has been approved). If the test email works, you know that your setup is correct.
Once your sending limit request has been approved, you can “activate the plugin” using the button at the top of the settings screen. Once you do that, all emails sent from WordPress using wp_mail() will now be sent using Amazon SES and your email delivery woes should be a thing of the past.