How to Set Up the Gmail Mailer in WP Mail SMTP

Would you like to use your Gmail or G Suite account to fix delivery issues on your site? WP Mail SMTP’s Google mailer option uses Google’s API to securely authenticate your site’s emails and help them to delivery successfully.

In this tutorial, we’ll show you how to set up WP Mail SMTP using the Google mailer with your Gmail or G Suite email address.


1. Install the WP Mail SMTP Plugin

To get started, you’ll need to install and activate the WP Mail SMTP plugin.

Once you’ve installed and activated the plugin, go to WP Mail SMTP » Settings. At the top of the Settings page, you’ll see a From Email option. You can skip this, as Google will force the From Email to match the email account you’ll add a little later in this tutorial (later on, you’ll notice this field becomes disabled).

Adjust From Email in WP Mail SMTP settings

Below the From Email, you can set the From Name. This is the name associated with emails sent out, and by default will be set to your site’s name. You can adjust this to any value you’d like. You can also check the Force From Name option to apply this setting site-wide.

Adjust From Name in WP Mail SMTP settings

Next, you’ll need to scroll to the Mailer field and select the Gmail option.

Select Gmail mailer in WP Mail SMTP

We also recommend checking the optional Return Path checkbox to Set the return-path to match the From Email. With this enabled, you’ll be emailed if any messages bounce as a result of issues with the recipient’s email.

Set return path to match From Email

Now that you’ve chosen the Gmail mailer, you should see a new section appear titled Gmail. Under this, there will be settings named Client Secret and Client ID.

Client ID and Client Secret fields in WP Mail SMTP

To generate the information needed for these fields, you’ll need to use your Google account to create a web application. This process doesn’t require any coding, and we’ll show you exactly what to do in the next step.

2. Create a Web App in Your Google Account

We’ll be coming back to WP Mail SMTP’s setting page a little later, so for this next step you’ll need to open a new tab or window in your browser. In that new tab/window, sign into your Gmail account and access Gmail’s application registration. Clicking that link should direct you to the exact page you need.

Note: If you’re using G Suite, make sure that the Google account you use has email sending permissions (in other words, access to its own inbox).

After you’ve followed that link and logged into your Gmail account, you’ll see a form named “Register your application for Gmail API in Google API Console”.

In the dropdown named Select a project where your application will be registered, leave the default option called Create a project. When you’re ready to move forward, click the Continue button.

Create a new project for Google application

Once you’ve clicked this button, Google will tell you “The API is enabled”. To move forward to the setup page, go ahead and click the Go to credentials button.

Gmail API is enabled

In the next page, you’ll be asked a few questions to help Google determine the credentials you need. Here’s how you should answer each question:

  • Which API are you using? Gmail API
  • Where will you be calling the API from? Web server (e.g. node.js, Tomcat)
  • What data will you be accessing? User data

Once you’ve answered these questions, click the What credentials do I need? button.

Add credentials to Gmail app project

After clicking this button, Google will show a popup asking you to set up a consent screen. Go ahead and click on the Set Up Consent Screen Option.

Open OAuth consent screen

This will open a new tab or window. Be sure to keep the original tab/window open, as we’ll return to it a little later.

In the new tab/window, you’ll be asked for several details to prepare your consent screen. This is the permissions screen that will display to you later in the setup process (never seen by your users).

If you have a G Suite account, you’ll first set Application type to Internal. You will not see this option if you’re using an @gmail.com email account.

Select internal application type

For Application name, you can add the name of your website (or any other name that feels logical to you).

Fill in Google app details

Then, you can skip down to Authorized domains and add the URL for your website. Be sure to not include http:// or https:// here.

For Application Homepage link, Application Privacy Policy link, and Application Terms of Service link, you can again just add your website URL. You don’t need to have special privacy or terms pages in place for this app, as again this consent screen will only ever be seen by you.

Add authorized domain information to Google consent

When you’re ready, click the Save button at the bottom of this screen.

After saving your consent screen settings, Google will take you back to an API credentials screen. You can ignore this, and instead return to the first tab/window.

For this step, you’ll be creating an OAuth client ID. OAuth, or Open Authorization, is what will provide permission for your website to use your Gmail account to authenticate emails.

For the Name field, enter anything you like or leave the default name. This is only for reference within your Google account.

For Authorized JavaScript origins, you’ll need to enter your site’s URL.

Last, we need to fill out the Authorized redirect URIs field. To get the URI for your site, you’ll need to go back to the tab or window with your WordPress site. Still on the Settings » WP Mail SMTP page, you’ll need to look under the Gmail section for the field labeled Authorized redirect URI.

The value in this field should be your site’s URL followed by some extra details. You’ll need to copy this value, which is easily done by clicking the button with the copy icon.

Use button to copy authorized redirect URI from WP Mail SMTP settings

After copying the URI, return to the Google APIs page and paste it into the field under Authorized redirect URIs.

Note: In order to be certain that Google stores your data, enter the URL and then tap the Enter/Return key. When you see a trash can icon next to the URL, you’ll know it’s been stored and it’s ok to proceed.

Create OAuth client ID

When you finish filling out these details, you may see a Refresh button near the bottom of the page. Go ahead and click this.

Click Refresh button

Next, you can click the Create client ID button.

Click blue button to create OAuth client ID

You’ve now successfully created a Google web application!

Now we need to see the full details. On the last screen, click I’ll do this later to go to the Credentials page.

Click Ill do this later

3. Grant Permissions and Send Test Email

On the Credentials page, you can now see the details of the web application you just created. To view Client ID and Client Secret, click the pencil icon.

Click pencil icon to see details

This will open all of the details for your app. On this page, you’ll see the Client ID and Client secret values.

Copy Client ID and Client secret

Each of these will need to be copied into your WP Mail SMTP settings back in your WordPress admin screen.

Note: Be very careful not to copy any extra text or spaces with your Client ID or Client Secret, as this will result in an error in the next step.

Copy in Client ID and secret to WP Mail SMTP settings

After saving these settings, the page will refresh. Before Google allows this information to be used to connect to your account, however, you must grant permission.

To do this, scroll to the bottom of this page and click the button labeled Allow plugin to send emails using your Google account.

Authorize plugin to send emails with Gmail

This will open a login screen for Google. Go ahead and log into the account you’re setting this SMTP up with. Then, you’ll see a screen asking for permission for this site to send email on your behalf.

When you’re ready, click the Allow button to proceed.

Provide permissions to your Google app

Next, you’ll be returned to your WP Mail SMTP settings and a success message will be displayed. Now that the connection is complete, you’re ready to send a test email under the Email Test tab.

Gmail connection success with WP Mail SMTP

Once the Test Email tab is open, you’ll need to enter a valid email address and click the Send Email button. Be sure to use an email address you have access to so you can confirm the email is delivered.

Send test email in WP Mail SMTP

When the test message has been sent, you’ll see a success message at the top of this tab.

WP Mail SMTP test email was sent successfully

You should also soon receive a test email at the email address you entered.

Test email for WP Mail SMTP Gmail

Frequently Asked Questions

What If the Test Email Doesn’t Send Successfully?

If the SMTP test email isn’t able to send, a debug log will appear with additional details. Here are some of the possible error messages and how to resolve them.

401. That’s an error.
Error: invalid_client

This error appears when the Client ID isn’t able to be read properly. To fix, try copying the Client ID in again and check that there’s no whitespace or extra text.

400. That’s an error.
Error: invalid_request
Missing required parameter: client_id

This error will display when the Client ID field is empty or not able to be read properly. To fix, copy in the Client ID again and be careful to not add extra text or whitespace.

cURL error 60: SSL certificate problem
This message means that the server is missing a certificate that’s required for SMTP to work. To fix, you’ll need to contact your site’s hosting provider to ask them to install this certificate (most likely the cacert.pem certificate, though it’s best to ask your host to check).

“code”: 401,
“message”: “Login Required”

If you see this in the debug message, permission still needs to be granted to your use Google account. For instructions on how to fix this, please see Step 3 of this tutorial. Also, be sure to check that the From Email in your SMTP settings matches the email used to setup the Google app.

What If I See a Screen Saying “This app isn’t verified”?

When you click the Allow plugin to send emails using your Google account button, Google might display a screen that says “This app isn’t verified. This app hasn’t been verified by Google yet. Only proceed if you know and trust the developer.” There’s no need to worry, though — the message is only referring to the app that you just created in your own Google account (so you are actually the developer in this case).

To bypass this message, you’ll need click Advanced and then Proceed.

This app isnt verified error

What If I Want to Switch to A Different Email Later?

If you’d like to change to a different Gmail/G Suite email address, you’ll need to repeat all tutorial steps above. This includes generating a new Client ID and Client Secret under this other email account.

When you get to the Authorization step (under Step 3), save your settings and then click the Remove Connection button. This will remove the authorization for your original email account and allow you to repeat the authorization steps with the new email.

Remove connection in WP Mail SMTP

That’s it! You’ve now set up WP Mail SMTP’s Google mailer on your WordPress site.