Send WordPress Emails With Gmail SMTP

[UPDATED] How to Send WordPress Emails With Gmail in WP Mail SMTP

Do you want to use Gmail SMTP in WordPress?

Sending WordPress emails through Gmail helps to improve deliverability and stop your WordPress emails from going to spam.

We’ll walk through the process of setting up Gmail SMTP securely in this guide:

  1. Install WP Mail SMTP
  2. Create a project in Google Cloud Console
  3. Switch from Testing to Production (free Gmail accounts only)
  4. Connect WordPress site to Gmail
  5. Set up your From Email and default Gmail alias
  6. Enable email logging in WordPress
  7. FAQs and troubleshooting

First, let’s understand how we’re going to link your WordPress site to Gmail SMTP.

Create Your WordPress Form Now

How Do I Link My WordPress Email to Gmail?

You can use WP Mail SMTP to link your WordPress email to Gmail via:

WPForms is the best WordPress Form Builder plugin. Get it for free!
  • Gmail SMTP details
  • Google API

We highly recommend that you use the Google API. This method takes a little longer to set up, but it’s worth it for the extra security, because:

  • There’s no need to share your Google account password
  • You don’t need to allow less secure apps in your Google account
  • You don’t need to type your Google SMTP or account login details into WordPress.

The WP Mail SMTP plugin has a setup wizard that makes it easy to connect your WordPress site to the Gmail API. We’ll show you how to do it in this article.

Why Use WP Mail SMTP?

WP Mail SMTP lets you send WordPress email through Google SMTP or the Google API. Either of these methods is more reliable than using the PHP mail function, which is the WordPress default.

WP Mail SMTP

Many email servers have learned to block emails sent via PHP mail. Emails that are generated this way ‘look’ like spam. They don’t have any authentication in the header of the email, which is the technical part that we don’t normally see.

With WP Mail SMTP, you can authenticate emails through your Gmail or G Suite account to keep your login details safe and private.

WP Mail SMTP will also work for you if:

  • SMTP ports are blocked, which is a common problem on some hosting providers and Amazon EC2
  • You’re using localhost and you want to send email from your site
  • Your hosting provider isn’t configured to use PHP mail for some other reason.

Let’s go ahead and take a look at how to set up WP Mail SMTP to send emails through the Gmail API.

How to Send WordPress Emails Using Gmail SMTP with WP Mail SMTP

This step-by-step guide will show you how to set up the Google API for WordPress SMTP.

The whole process can take a while. We recommend keeping this guide open in a tab so you can follow the steps as you work through it.

If you’re not sure that you want to tackle this yourself, keep in mind that WP Mail SMTP Elite comes with a full White Glove Setup service for Mailgun or SMTP.com.

Step 1: Install WP Mail SMTP

The first thing you need to do is to install and activate the WP Mail SMTP plugin.

For step-by-step instructions, you can check out WPBeginner’s guide on how to install a WordPress plugin.

When you activate the plugin, the setup wizard will open. Click Let’s Get Started to begin.

WP Mail SMTP Setup Wizard

Next, you’ll be asked to select your mailer. Go ahead and click Gmail.

Select Gmail in WP Mail SMTP setup wizard

WP Mail SMTP will show you a notification about the limitations of using Gmail with WordPress.

One issue to keep in mind is that Gmail and G-Suite both have account-wide email sending limits.

Google Account Type Email Sending Limit (per day)
Google (free) 500
G-Suite / Google Workspace 2000

These limits apply across your entire Google account. So any emails sent from Google products (like Google Forms notifications) will count towards this cap. The emails you send from your regular mailbox count towards it too.

So, what does this mean? If you have a busy website or a WooCommerce store, you may run into issues because the API isn’t designed to handle lots of transactional emails.

If you’re happy to continue, let’s keep moving through the setup steps.

On the next screen, WP Mail SMTP will prompt you for 2 things:

  • Client Secret
  • Client ID

It’ll also display the Authorized Redirect URI, and we’ll need to copy that in a minute.

For now, pause the setup. At this point, we’ll set up your new Google Cloud app.

Step 2: Create a Project in Google Cloud Console

Now we’re ready to switch over to Google and set up the new app. This will create an API connection that you can use in WP Mail SMTP, and it means you never have to reveal your account username and password.

Start by opening up the Enable an API screen in Google Cloud Console. (Clicking this link will take you directly to the Enable an API screen in a new tab.)

You may be asked to agree to the Terms of Service if it’s your first time using Google Cloud Console.

Next, from the dropdown, select Create a Project and click Continue.

Create a Project in Google Cloud

You may see a slight pause and see an Enabling API popup.

When the next screen loads, click Go to Credentials.

Go to Credentials in Google Cloud

Now we can set up the credentials for your app.

As you move through the rest of these screens, be sure to click Next at the end of each section. If you click Done, you will exit the set-up process without completing it.

Credential Type

Now we’ll tell Google how to set up the API.

Under Which API are you using, go with the default selection: Gmail API.

Gmail API

Then scroll down a little to What data will you be accessing?

Go ahead and select User data and click Next.

Create credentials screen

Next, we need to set up a consent screen. Nobody will ever see this, but we need to do it before we can publish your app.

Click Next to move on.

Now we’ll set up your App Information.

The details in this form aren’t super important because nobody else will be using your app. Here’s what we suggest:

  • Type in an Application name that makes sense to you
  • Pick your email from the User support email dropdown
  • You can safely skip the logo.

Consent screen settings in Google Cloud

In the Developer email field, type your own email address.

Set developer email in Google Cloud

Now hit Save and Continue to move on to Scopes.

Scopes

Scopes aren’t required for your app, so we don’t need to use this section.

Scroll past the entire section and hit Save and Continue again.

Save and continue Scopes in Google Cloud

Now we’re ready to set up the Client ID.

OAuth Client ID

In this section, we’re going to set up the Client ID that we need for WP Mail SMTP to connect to your Google account.

In the OAuth Client ID dropdown, select Web application.

OAuth web application

You can change the Name if you want, but it’s fine to keep the default.

In the next 2 fields, you’ll want to type in the following information:

  • Authorized JavaScript origins: Type your site URL starting with http:// or https://
  • Authorized redirect URI: paste in https://connect.wpmailsmtp.com/google/

Hit Create to complete this step.

When Google prompts you to download your credentials, copy the Client ID it shows you.

Copy Client ID in Google Cloud Console

Switch over to the browser tab we were using earlier. In the WP Mail SMTP Setup Wizard, paste in the Client ID.

Client ID in WP Mail SMTP

We don’t need to save the credentials, so you can click Done.

Let’s grab the Client Secret now.

Switch back to Cloud Console. Make sure you’re still on the Credentials screen.

Credentials screen in Cloud Console

Find the credentials we just created under OAuth 2.0 Client IDs. Then click the pencil icon on that line.

OAuth client ID list

Look to the top right of the screen and copy your Client Secret.

Client Secret in Google Cloud Console

And now switch to WP Mail SMTP and paste that in.

WP Mail SMTP Client Secret

OK, we’re done, but don’t continue the wizard yet. If you’re using a free Gmail account, be sure to complete the steps in the next section to avoid issues with your new app.

Step 3: Switch From Testing to Production (Free Gmail Accounts Only)

If you have a free Gmail account, Google will have published your app in Testing mode.

It’s super important to change this setting.

If you skip this step, your Gmail integration may stop working every week. You may also see the message Token has been expired or revoked in WP Mail SMTP.

We’re going to edit your app to put it into Production. Google Workspace users don’t need to do this.

To switch from Testing mode to Production mode, go back to Cloud Console and click the OAuth Consent Screen in the left hand navigation pane.

OAuth consent screen

Under Publishing Status, click Publish App.

Publish app in Google Cloud Console

You’ll see the message Your app will be available to any user with a Google Account.

Don’t worry! Your account is secure.

No other user knows your Client ID and Client Secret, so they won’t be able to access your app. And WP Mail SMTP never asks for your Google username and password, so it’s completely secure.

When you’re ready to proceed, click Confirm.

Push Testing app to Production

And that’s it! Your app is now live in Google Cloud Console.

Step 4: Connect WordPress Site to Gmail

We’re almost done. As a final step, we need to connect WP Mail SMTP to Google. Without this, the app won’t be able to send email.

Switch back to your WP Mail SMTP browser tab. Scroll down past the Authorized Redirect URI.

Under Authorization, click the Connect to Google button.

Authorization - Connect to Google

This will open a login screen for Google. Go ahead and log in, then click the Allow button to grant permission for your site to send email.

If you see a warning that your app is not verified, don’t worry. Free Gmail users will see this because Google hasn’t checked it. But we don’t need them to because the app won’t be used by anyone else.

Go ahead and click Advanced and then Go to example.com (unsafe).

OAuth Gmail not verified

In WP Mail SMTP, you’ll see a popup confirming that the authorization worked.

Scroll all the way down to the bottom of the screen for the final step.

Step 5: Set Up Your From Email and Default Alias

WP Mail SMTP gives you the option of forcing all plugins and contact forms to use the same From Name if you want to.

This is a quick and easy way to make sure your customers and visitors always see the same Name in the sender field of every email.

You don’t have to force this setting. You can choose to enable it here if you want to.

Force From Name for Gmail in WordPress

Below that, there’s a From Email setting, and WP Mail SMTP will automatically show you all of the aliases set up on your Google Workspace or Gmail account.

The email address you pick in the dropdown here will be the default From email in WordPress.

From Email dropdown in WP Mail SMTP

Wondering how this works?

You can use any email listed in this dropdown to send email from WordPress. Just type it in as the From Email in your plugin or contact form settings, and WP Mail SMTP will authenticate the email for you.

The ‘primary’ email address that you select will be used as a fallback, or default sender. For example, if we created a contact form with a From Email of [email protected], that isn’t a registered alias in our Gmail account. So the From Email would be switched to our default selection here: [email protected].

Want to add more Gmail aliases here? Check out how to send WordPress emails from a Gmail alias for a complete guide to setting them up.

We’re almost done! Just 1 more option to check.

Step 6: Enable Email Logging in WordPress

WP Mail SMTP Pro includes complete email logging for WordPress.

At the end of the setup wizard, users of the Pro license or higher will see the option to turn this on.

Enable email logs in WordPress

You can use the built-in email logging tools to:

  • Track every email sent from your WordPress site
  • Search and track the delivery status of any email
  • Search, filter, and print email logs or save to PDF
  • Export email logs to CSV or XLS
  • View a deliverability chart on your WordPress dashboard.

WP Mail SMTP Pro dashboard widget

Want to use these awesome email logging features? Upgrade to Pro now!

When you complete the wizard, WP Mail SMTP will do a final check on your settings and automatically send a test email to your chosen address.

And that’s it! You successfully set up your WordPress email with Gmail and WP Mail SMTP!

Create Your WordPress Form Now

Gmail SMTP FAQs and Troubleshooting

Occasionally, our users run into issues with Gmail SMTP in WordPress. Here’s a quick collection of FAQs that will help to resolve any issues that you have.

What Do Testing and Production Mean in Google Cloud Console?

In Google Cloud Console, Production means that your app is live. This is the default setting for Google Workspace users. Testing is the default setting for free Gmail accounts.

While Testing mode will work, it has a 7-day timeout. So every week, your emails will stop working and you’ll have to reconnect the app.

To fix this, put your app into Production mode.

What Do the Options “Internal” and “External” Mean?

In Google Cloud Console, Internal means that the app will be available to your organization. This is the default setting for Google Workspace users.

External means that the app will be available to any Google account. This is the default setting for free Gmail accounts because they aren’t part of an organization.

You don’t need to worry about this setting. You can go ahead and use the default that Google selects for your account.

Why Can’t I Use My Domain For the “Authorized Redirect URI”?

The Authorized Redirect URI is only used when you connect your site to Gmail the first time. We provide our own URL for this initial connection so that you don’t experience any issues with security plugins or mod_security on your server.

Why Do I See a DMARC, SPF, or DKIM Warning?

WP Mail SMTP has a built-in Domain Checker. It automatically scans your domain’s DNS records for rules called DMARC, SPF, and DKIM and will warn you if they are missing.

If you’re using Google Workspace or a custom domain with Gmail, we recommend adding these to your DNS. Jump down to our table of common Gmail errors for instructions.

Free Gmail users (without a custom domain) can ignore these warnings. As a free Gmail user, you don’t have control over the sending domain’s DNS, so you can’t add these records.

Why Do Emails From WordPress Appear in the Sent Folder in Gmail?

When WP Mail SMTP sends email using the Google API, it’s essentially the same as you sending them yourself from your ordinary mailbox. So every email that’s sent from your site will appear in your Sent Mail folder in your mailbox as well.

If you don’t want this to happen, we recommend that you choose a different mailer like SMTP.com or Sendinblue.

How Do I Switch Gmail Accounts in WP Mail SMTP?

If you want to send email from a different Gmail address in WordPress, you have 2 options.

Use a Gmail Alias

WP Mail SMTP lets you send emails from multiple Gmail or G-Suite aliases. So if you want to use a different From address, you can easily add it as an alias in your Google account.

To learn how to add an alias and use it in WordPress, check out how to send WordPress emails from a Gmail alias.

Switch Google Accounts

If you’d like to change to a different Gmail/G Suite email account, you’ll need go to WP Mail SMTP » Settings and click the Remove Connection button.

Remove Gmail connection

After disconnecting your account, scroll up to the Mail section and click Launch Setup Wizard to create a new Gmail SMTP connection.

Launch Setup Wizard in WP Mail SMTP

Remember: clicking Launch Setup Wizard will erase your existing settings, so it’s best not to click it unless you’re ready to switch.

Now let’s list some common error messages and solutions in case you run into a different problem.

Gmail Error Messages + Solutions

Error Message Solution
  • Invalid grant
  • Token has been expired or revoked
  • Error 403: access_denied
    The developer hasn’t given you access to this app. It’s currently being tested and it hasn’t been verified by Google.
Your Google app is likely still in Testing mode. While this will work, your connection will break every 7 days.

To fix this, it’s easy to put your app into Production mode.

  • 401. That’s an error. Error: invalid_client
  • 400. That’s an error. Error: invalid_request Missing required parameter: client_id
Head to WP Mail SMTP » Settings and click the Launch Setup Wizard button. Copy the Client ID in again.

Check that there’s no whitespace or extra text at the start or end of the Client ID.

cURL error 60: SSL certificate problem Contact your site’s hosting provider to ask them to install this certificate. It’s most likely the cacert.pem certificate, though it’s best to ask your host to check.
401
Login Required
Head to WP Mail SMTP » Settings and click the Launch Setup Wizard button. Run through the Setup Wizard again and be sure to connect your Google Account to WP Mail SMTP.
Request is missing required authentication credential.
Expected OAuth 2 access token, login cookie or other valid authentication credential.
This means your Gmail setup is not complete. Head to WP Mail SMTP » Settings and click the Launch Setup Wizard button to check your settings.
Google hasn’t verified this app
The app is requesting access to sensitive info in your Google Account.
To bypass this message, you’ll need to click Advanced and then Proceed.

Don’t worry – your app does not need to be verified by Google to work.

Action Needed: It doesn’t look like the SPF record required by Google has been added to your domain.
Please check out Google’s SPF guide for details on how to add this record to your domain’s DNS.
WP Mail SMTP can’t find an SPF record in your DNS. Adding an SPF record could help improve email deliverability.

If you’re using Google Workspace or a Gmail account with a custom domain, follow Google’s tutorial to solve this.

If you’re using a free Gmail account without a custom domain, you can ignore this warning.

Action Needed: It doesn’t look like the DKIM record required by Google has been added to your domain.
Please check out Google’s DKIM guide for details on how to add this record to your domain’s DNS.
WP Mail SMTP can’t find a DKIM record in your DNS. Adding a DKIM record could help improve email deliverability.

If you’re using Google Workspace or a Gmail account with a custom domain, follow Google’s tutorial to solve this.

If you’re using a free Gmail account without a custom domain, you can ignore this warning.

Action Recommended: It doesn’t look like DMARC has been set up on your domain (example.com).
We recommend using the DMARC protocol because it helps protect your domain from unauthorized use.
Please check out our step by step guide for details on how to add this record to your domain’s DNS.
WP Mail SMTP can’t find a DMARC record in your DNS. Adding a DMARC record could help improve email deliverability.

If you’re using Google Workspace or a Gmail account with a custom domain, read how to add a DMARC record to your domain. This article includes a generic DMARC example you can copy and paste.

If you’re using a free Gmail account without a custom domain, you can ignore this warning.

If your error message isn’t listed here, you can contact WP Mail SMTP support:

Create Your WordPress Form Now

Next, Grow Your Website Traffic

Now that your emails are sending perfectly, it’s time for explosive website growth. You can start by hosting a giveaway on your website and trying some easy tips to reduce form abandonment.

Ready to build custom WordPress forms? Get started today with the easiest WordPress form builder plugin. WPForms Pro includes 100+ free templates and offers a 14-day money-back guarantee.

If this article helped you out, please follow us on Facebook and Twitter for more free WordPress tutorials and guides.

Using WordPress and want to get WPForms for free?

Enter the URL to your WordPress website to install.

Comments

  1. This well-written how-to is really helpful to total beginners like me. You mention that WP Mail SMTP will work with local hosting. To do this, is it just a matter of entering the localhost:8888 address at the point where you say ‘ Type your site URL…’?

  2. I have done the above steps (I’m gsuite customer) and everything works well when I try to ‘Connect to Google’. I even get a message from Google saying that the app I created wants to connect to access my Google account. However, when I say ‘Allow’ I get the error:

    Not Found
    The requested URL was not found on this server.

    Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

  3. I have no issues to set up this but the only issue I have been suffering is, I have to remove the connection over and over again every 1-2 weeks in WP mail SMTP, then re-authorize this APP so the WP mail can work again on my WordPress website.

    I have published the APP to Production Mode but I still don’t know what causes this.

    Can you advise?

    1. Hi Gats!

      Usually when we see this invalid grant issue of a Gmail mailer repeatedly disconnecting from WP Mail SMTP, it means that your Google API app (oAuth screen section) is in the “Test mode” and needs to be changed to “Production” to resolve this issue.

      Can you please look into adjusting this setting in Google’s API & Services > OAuth consent screen > Publishing status area and see if it resolves this issue for you?

      Other Causes to Gmail Disconnections

      The OAuth token in Gmail will reset for any event breaking the connection, including but not limited to:

      -Changing google password
      -Enabling or disabling 2fa
      -Google account access reset
      -Activation of Google advanced protection program
      -Revocation of the app to profile
      -App oAuth permission revoked by Google
      -App moved from public mode to private/internal mode by Google (or by a user whose user domain is not in the allowed org domain zone)
      -App verification failure on reaudit
      -Suspension of Google account
      -User requested linked account unlinking
      -The user does not use the app for 6 months (automatically expires refresh token)
      -The user adds/removes sensitive or needs review scopes to the app but does not complete the app review process
      -If the user is at the maximum limit for OAuth tokens to a Google profile (50) or for the service (25 for example in analytics), activation of a new refresh key will also automatically revoke the earliest key

      To resolve the issue, please head over to WP Mail SMTP -> Settings page, and click on the “Remove Connection” button. Then click on the “Allow plugin to send emails using your Google account” button and re-enable access.

      Also, in some cases, this could be that the request from Google has been blocked by firewall rules in your server or most likely the mod_security apache module. In those cases, you would need to contact your hosting provider to fix the issue. Unfortunately, we don’t have much control over that.

      I hope this helps! For more support with WP Mail SMTP, please feel welcome to submit a support ticket if you have a WP Mail SMTP license.
      Otherwise, we provide limited complimentary support in the WP Mail SMTP WordPress.org support forum.

      1. Hi Henry,

        Thanks for the reply. However as I said in my post, I have already switched the testing mode to production, but the issue just constantly happens every 1-2 weeks.

        Therefore, I have removed the former info on WP mail settings and use new info by created another project with Google API, was following the instructions here. Let’s see if the issue will happen again.

        Thanks.

      2. Hi Gats! As we’re not supposed to do troubleshooting here, I was trying to provide as much information as possible at once. I apologize for any misunderstanding around that.

        Also as this is a WP Mail SMTP related matter, it would be best if you reached out to their team for further assistance on the matter as they would have more experience and be more knowledgeable about matters related to their plugin.

        For more support with WP Mail SMTP, please feel welcome to submit a support ticket if you have a WP Mail SMTP license.
        Otherwise, there is limited complimentary support in the WP Mail SMTP WordPress.org support forum.

        Thanks!

    1. Hey Adriana- I am sorry to hear about the trouble you are facing here!

      For Error 400: redirect_uri_mismatch please check if there’s no whitespace or extra text at the start or end of the Client ID. Please refer to the FAQ section of the Gmail Mailer guide

      If you have a WP Mail SMTP license, you have access to the email support, so please submit a support ticket. Otherwise, we provide limited complimentary support in the WP Mail SMTP Lite WordPress.org support forum.

      Thanks 🙂

  4. I have the 403 error. I was not able to switch the mode for testing to production because my url is http, not https. So, what can I do?

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.