How to User Gmail to Send WordPress Emails
In order to prevent abuse, some web hosts have email restrictions, so they require a third-party service to send a large volume of emails from your WordPress site. Haven’t you noticed some major hosts don’t even offer email hosting and site hosting together? This is great for preventing spam, ensuring your site isn’t on a blacklisted IP address and reduces the unnecessary strain on your server.
You can set up a third-party email service for your WordPress site easily using an SMTP or Email API plugin. Many email service providers such as G Mail are also free depending on volume of emails you send, so you can get better solution without additional costs.
In this post, I’m going to teach you how to configure the WP Mail SMTP plugin to use the Gmail API for sending WordPress emails. I’ll also teach you a faster and multisite-friendly way to set this up using WPMU DEV’s Ultimate Branding plugin. We’ll go over why using a third-party email provider is imporant and look at some popular transactional email service providers.
If you’re starting to notice that emails from WordPress, like password resets and contact form notifications, are slow to arrive or not arriving at all, this post will help you fix those issues.
Signed, Sealed, Message Not Delivered
Ideally, you should set up a third-party hosting before email deliverability becomes a problem, because most email issues are difficult to detect and can damage your reputation.
For one, your users might not report these issues to you. After attempting to reset their password or signing up for a service and not receiving an email, for example, your users may give up and move on.
Your site host will not report server issues because they don’t want to call attention to the fact that they’re falling short and aren’t able to deliver your emails. This isn’t true for all hosts though, some do have email failure logs.
For developers and implementers, you’ll usually recognize there is a problem when a WordPress form on your site has stopped sending notification emails. By then, you’ll probably have a stack of unanswered messages that have piled up over a few weeks which won’t paint your customer service in the best light. Ouch.
Transactional Email Providers
Although there are plugins that will allow you to send bulk emails like newsletters and promotions from WordPress, WordPress isn’t the best tool for the job so you should choose a dedicated service such as MailChimp, Constant Contact, Aweber, Active Campaign and Campaign Monitor.
Transactional emails are automated emails your user requests like password resets, receipts and signup confirmations. These one-to-one emails from WordPress are important and initiated by the user so they’re not likely to be marked as spam. Transactional email providers, like the following, can help you deliver these emails.
Gmail is a great option if you’re already using it for your business emails, because it’s free. We’re going to go over how to use Gmail to send transactional emails later on in this post. Gmail does have a sending limit of 500 emails per day and this will also include manual emails you send out in your day-to-day activities. G Suite‘s daily limit is 2000 but only 500 for trial accounts, so that’s something to keep in mind. We’ll go over how to configure Gmail/G Suite later in this post.
Mailgun verifies email addresses to ensure they’re valid so you won’t waste resources sending emails to phony addresses. Mailgun is free for your first 10,000 emails a month and has their own WordPress plugin.
Sendgrid offers marketing emails and transactional emails. SendGrid has a less generous free option than Mailgun. With SendGrid, you can send 40,000 emails for 30 days for free, then send 100 emails/day free forever. SendGrid also has a dedicated WordPress plugin.
Mandrill and MailChimp
Mandrill is a paid extension for MailChimp. They don’t have a free option anymore but they do have their own WordPress plugin which makes the integration process easy.
Here’s some additional transactional email providers who may suit your needs better than the ones above:
Apple of My API
When it comes to integrating WordPress with a Third-Party Transactional Email service provider, should you choose to use their web API or use SMTP relay? Here’s what you need to know about each.
SMTP is a global standard and it’s been around for a very long time; however, because bits and pieces have been added over the years it’s not as cohesive or efficient as something that was conceived as a whole. SMTP is widely available so it’s a viable option for legacy systems.
When WordPress uses SMTP to send messages through your email service provider, there is a lot of back and forth between the two systems in order to check the message, DNS records and authentication, so there is multiple points of potential failure. This also means that SMTP is slower than web APIs because of all the back and forth.
As for web APIs, each email service provider’s API will be different and not all providers have one. Connecting WordPress via an API will allow you to access additional functionality that is not available via SMTP. Some of the benefits include an extra layer of security because of the use of API keys, detailed reporting so troubleshooting is easier and some providers allow you to send a higher volume of emails via their API.
Keep these things in mind as you explore email service providers.
I’m going to teach you how to use both Gmail SMTP and the Gmail API so you’ll be able to choose the one that best meets your needs.
How to Use the Gmail API to Send WordPress Emails
Gmail and G Suite are a great option for sending a few emails because you or your client probably already have a Google account. Also, since Gmail has an API, well get much better deliverability and performance.
To integrate Gmail/G Suite with WordPress, we’re going to use the WP Mail SMTP plugin that’s available on WordPress.org. With over a million installs, this plugin allows you to easily integrate WordPress with Gmail, SendGrid, Mailgun and it has an option for a custom SMTP setup.
To begin the integration process, you need to install the WP Mail SMTP plugin on your WordPress site.
Once the plugin is installed, go to Settings > WP Mail SMTP to set who the email will come from. You’ll need to enter the Gmail or G Suite email address that you’re going to be sending emails from and a name. The name does not need to match the name in Gmail/G Suite.
If you want all the emails on your site to come from your Gmail/G Suite address, select the Force from Email checkbox. This will save you trouble of having to change it manually everywhere. You can do this for name as well.
Select the Return Path checkbox to receive bouncebacks in your Gmail inbox.
When you’ve completed that, scroll down and select the Gmail option. This will open additional fields that we’ll need to configure Gmail/G Suite.
Gmail Apps and Zerts
In order to continue configuring Gmail, we’re going to need to create a Gmail app, which is a whole lot easier than it sounds. There’s no coding required. We just need to create credentials for the WP Mail SMTP plugin to use to integrate WordPress and Gmail.
Do not close the WP Mail SMTP plugin settings page because you’re going to need it in a bit.
To create a Gmail app, sign in to Google’s application registration page for developers and create a project.
Once you do that, you’ll see a confirmation message that the API is enabled. Hit the Go To Credentials button to create your credentials to access the API.
There’s three steps you need to complete to create credentials for your project.
Step 1: Determine What Credentials You Need
Luckily the form will help you determine what kind of credentials you need.
- For the Which API are you using? dropdown, select Gmail API
- For the Where will you be calling the API from? dropdown, select Web Server (e.g. node.js, Tomcat)
- For the What data will you be accessing? question, select User Data
Then push the What credentials do I need button?
Step 2: Create OAuth 2.0 Client ID
Second, you’ll create an OAuth 2.0 Client ID. This is how WordPress will gain permission to use your Gmail API.
In the name box, you can leave the default or enter a custom name. Your users won’t see this information so the default is fine.
For box number 2, you need to go back to your WordPress site and on the settings page for the WP Mail SMTP plugin, in the Gmail section, copy the Authorized redirect URI and paste it in box number 2 (as seen above) in Google.
1.6 million WordPress Superheroes read and trust our blog. Join them and get daily posts delivered to your inbox – free!
Then push the Create OAuth Client ID button in the Google API.
Step 3: Set Up OAuth Consent Screen
The third step is to set up the OAuth consent screen. Since WordPress is going to be using your Gmail app and not actual users, your users won’t see this consent screen.
Just make sure your email is selected and in Product Name Shown to Users enter the name of your site. Then select the Continue button.
We don’t need our newly created credential information in JSON, so we’re going to bypass the next screen by hitting I’ll do this later since there’s not an I’ll do this never option 🙂
We’ll get the client ID and client secret together in the next step, so you don’t have to copy it from here, but you can if you want to.
On the next screen, we’re going to hit the pencil icon to retrieve our client secret and client ID.
This will take us our credentials, finally!
You’ll copy the client ID and client secret and go back to the WP Mail SMTP settings page to enter them there.
Then select the Save Settings button which will refresh the page and once that happens, scroll down and select the Allow plugin to send emails using your Google account button.
Almost done. Once you select the Allow plugin to send emails using your Google account button, you’ll be redirected to Gmail to sign in and allow WP Mail SMTP to use your account.
You’ll be redirected back to the WP Mail SMTP page and see a confirmation message.
And we’re done. Bring on the zerts to celebrate.
Once you switch over to sending emails with the Gmail API, you’ll be able to send newsletters from WordPress without putting extra pressure on your server.
Using Gmail to Send WordPress Emails Using Ultimate Branding
Ok, that was a bit of a process. There is an easier way to use Gmail to send emails on behalf of WordPress using your Gmail/G Suite credentials using Ultimate Branding. The Ultimate Branding plugin does not require you to set up a Gmail app and create OAuth credentials.
This setup also works for multisite, although all of the emails from the sites in your network will come from the same address and be subject to the limits of a single Gmail/G Suite account.
To assist with deliverability, improve security, and maximize the number of emails you’re able to send, you should create a separate Gmail/G Suite address. Creating a [email protected] email account and only enabling less secure apps on that account, will preserve the security settings on your personal Gmail/G Suite account.
Configuring Ultimate Branding to use Gmail SMTP is a 3 step process.
Step 1: Enable “Less Secure Apps” to Access Gmail
Less Secure? Oh, my! Actually, “Less Secure” in Gmail and G Suite just means an application that is using your Gmail address and password instead of OAuth for authentication. As a matter of fact, if you’re using an email program, such as Outlook, to manage your email, then you might have already enabled this feature.
How to Enable Less Secure Apps in Gmail and G Suite
To enable apps to access Gmail and G Suite, log in to your Google account at myaccount.google.com. Select Sign In and Security.
Near the very bottom of the page, you’ll see a box that says Allow less secure apps. Switch this to on. If you are using G Suite and this setting isn’t visible, you or your organization admin need to allow users to access this setting. Continue to the next section and I will show you how.
How to Allow Access to Less Secure Apps in G Suite
If you are the G Suite admin and you want to allow users to access the setting for apps, go to admin.google.com. You’ll be prompted to sign in. Select the Security icon.
Open basic settings.
In the basic settings box near the bottom, click on the link that says Go to Settings for Less Secure Apps.
Select the Select Allow Users to Manage Their Access to Less Secure Apps radio button.
Then follow the instructions above to allow less secure apps in your dedicated Gmail account (not the admin account).
Step 2: Installing Ultimate Branding and Activating SMTP
Once you’ve enabled apps to access Gmail, you’re ready to install the Ultimate Branding plugin. You’ll activate SMTP from the Ultimate Branding settings page and then you’ll go to the SMTP tab that appears.
Step 3: Configuring Ultimate Branding SMTP
All of the configuration settings for Ultimate Branding appear on one page. There’s 9 settings you need to configure to get started.
- For From Email Address, Enter your Gmail/G Suite email address that you will be sending emails from
- If you wish to specify the name that all your emails will come from, select On for Force from name replacement, then enter the name you would like to use.
- For SMTP host, whether you’re using Gmail or G Suite, enter smtp.gmail.com
- For Type of Encryption, select the SSL radio button
- For SMTP port, enter 587
- For SMTP Authentication, select On
- For SMTP Username, enter the same email address you entered in step 1 (From email address). These must match
- For SMTP Password, enter the password for your Gmail or G Suite account.
- Make sure Allow Insecure SSL Certificates is set to Disallow
Then scroll to the bottom of the page and push the Save Settings button. After the page refreshes, you can send yourself a test message to ensure you configured Ultimate Branding properly.
To send a test email, scroll to the bottom of the configuration page, enter an email recipient and push the Send test email button.
That’s a Wrap
As I mentioned earlier, every host has a different email volume threshhold, so I recommend reconfiguring WordPress to use an email service as soon as possible. The first time this happened to me, I couldn’t figure out the issue for a few weeks because the issue would come and go. Now, shortly after I launch a site, I configure a third-party email provider in less than half an hour and save myself the headache later.
Also, when all your emails come from the same name and address, it’s easier for your users and clients to trust you and recognize you, which solves a lot of problems before they begin. When you switch over, you’ll also realize how many of your emails were ending up in spam because you’ll see improvements across certain metrics. You might have a higher email open rate, because people are actually getting your emails. You might have more returning visitors, because people can reset their passwords.
You’ll start to see benefits immediately and you’ll wish you had switched over sooner.