Creating a Web App in Your Google Account
In a new tab or window you’ve opened, you’ll need to sign into your Gmail account and access Gmail’s application registration.
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).
Once you’ve logged into your Gmail account, you’ll see a form named Register your application for Gmail API in Google Cloud Platform.
For the Select a project where your application will be registered step, a new app will automatically be created for you in Google if you haven’t previously created one. Click on the Continue button.
You may be asked to agree to the Terms of Service if it’s your first time using Google Cloud Console.
Go ahead and agree to the Terms of Service, and select your Country of Residence from the dropdown menu. If you’d like, you can also optionally choose to receive newsletters from Google Cloud, however this is not required.
After you’ve configured each of these settings, go ahead and click the Agree and Continue button to move on to the next step.
Once you’ve clicked this button, you’ll see a confirmation message that says The API is enabled. To move forward to the setup page, go ahead and click the Go to credentials button.
Create Your Application’s Credentials
On the next page, you’ll be asked a few questions to help Google determine the credentials you need.
In the first step titled Credential Type, you should make sure the Gmail API is selected in the Which API are you using section. Under What data will you be accessing, select the User Data option and click on Next.
Note: If you don’t see an option for the Gmail API in the dropdown, be sure that you have the Gmail API enabled for your account.
Configuring Your OAuth Consent Screen
In this second step, Google will ask for some basic App information. This isn’t very important, since nobody else will be using your app, but some fields are still marked as required:
- App name – Input the app name of your choice, for example: WP Mail SMTP
- User support email – Select your email address
- App logo – Skip this option
Finally, add your email address in the Email addresses field and click on Save and Continue.
Configuring Scopes
Scroll down to the end of the Scopes section and click on Save and Continue. This section is optional, so we are skipping it.
OAuth Client ID
In the Application type dropdown menu select the Web application option. The OAuth Client ID step will update after you make your selection.
You can leave the Name default value or change it to something more relevant, for example: WP Mail SMTP.
Skip the Authorized JavaScript origins section and scroll to the Authorized redirect URIs, click on + Add URI button and input https://connect.wpmailsmtp.com/google/
.
Click on the Create button to complete this step.
At this point you are done with the Create credentials setup, so you can click on the Done button. Don’t worry about saving or copying the Client ID, we’ll do that a bit later.
Update publishing status from Testing to Production
This step is only for users with free Gmail accounts. Users with Google Workspace (formerly G Suite) accounts should skip this step.
Google will put your app into Testing mode by default. It’s really important that you switch to the Production mode, otherwise, your app will be super limited and will not function properly.
In the left side menu click on the OAuth consent screen.
In the Publishing status section you will see that the app is in Testing mode. Click on the Publish App button, to switch it to the Production mode.
A popup will show up with the “Your app will be available to any user with a Google Account.” message. Don’t worry, you are the only one that will have access to this app. This app will only be used in your WordPress site (in the admin dashboard area). Click on Confirm button.
3. Granting Permissions and Sending Test Email
In the left side menu go to the Credentials page. In the OAuth 2.0 Client IDs section you can now see the details of the web application you just created. To view Client ID and Client Secret, click the pencil icon.
This will open all of the details for your app. On this page, you’ll see the Client ID and Client secret values.
Go ahead and copy both of these values into your WP Mail SMTP settings. Once those have been added, click Save Settings at the bottom of the page.
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.
After saving these settings, the page will refresh. You must grant permission before Google allows our plugin to use your Gmail API to send emails.
To do this, scroll to the bottom of this page and click the button labeled Allow plugin to send emails using your Google account.
This will open a login screen for Google. Go ahead and log into the account you’re setting up SMTP with.
If you are connecting with a free Gmail account you might see the below screen. Google Workspace (formerly G Suite) users will not see it because their app is configured for internal use only, a setting, which is not available for free Gmail users.
Click on the Advanced link in the bottom left corner. In this expended section click on Go to wpmailsmtp.com (unsafe). Don’t worry, Google only displays this warning, because the app is not verified by them. There is no need for the app to be verified since you created this app just for your own use.
Next, you’ll see a screen asking for permission for this site to send emails on your behalf.
When you’re ready, click the Allow button to proceed.
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.
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.
When the test message has been sent, you’ll see a success message at the top of this tab.
You should also soon receive a test email at the email address you entered.
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 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.
Request Entity Too Large
Error 413
If you’re seeing this error, it’s likely that files being sent through your forms exceed Gmail’s limit for direct file attachment in emails. This limit is applied to the sum of the message’s text as well as the encoded attachment. To prevent this error, you’ll need to make sure that all files are no larger than 22 MB.
There was a problem while retrieving Auth for gmail: Could not json decode the token
This error is a possible indicator that another plugin (such as UpdraftPlus) is loading a different version of Google’s API on the site, creating a conflict. If possible, the conflicting plugin should be deactivated. Otherwise, it’s recommended that you set up another mailer.
If none of the above apply, or the test email still isn’t working
Your Google account may have the Gmail API disabled. To check on this, follow Google’s guide to enabling an API.