HomeTips and TricksHow to create a Gmail API and send Emails using SMTP Plugin

How to create a Gmail API and send Emails using SMTP Plugin

Gmail is one of the most popular email services so far, and you will very probably want to use it as a mailbox for your web or mobile app. It is safe and credible, which is crucial to prevent your emails from going into the spam folder. That’s why we decided to flesh out how to send emails with Gmail API.

Reason why that we recommend using SMTP to send emails in WordPress. SMTP (Simple Mail Transfer Protocol) is the industry standard for sending emails. Unlike PHP mail function, SMTP uses proper authentication which increases email deliverability.

There are many different SMTP services available, but in this article we will show only two Gmail option.

How to make your app send emails with Gmail API

Step 1: Create a project at Google API Console

You should start with Google Developers Console. Those who visit this page for the first time ever will have to agree with the Terms of Service and pick their Country of residence. Then click Select a project and create a new one.

Name your new project and press Create at the bottom. Give it a meaningful name so that next time you are here, you can easily recognize it.

Step 2: Enable Gmail API

Developer console will now create your project and take you to its dashboard. Google allow developers to access many of their APIs and services. Now that your project is setup, you need to enable the APIs that you will be needing. You can press the Library tab on the left and find yourself in the API Library page. Enter “Gmail API” in the search bar and click on it once found. Now, you need to enable the API for your project.

Note that you’ll have to enable it separately for each new project you work on.

Step 3: Credentials and authentication

Now that your API is enabled, the next step is to create credentials that you can use in your WP Mail SMTP plugin settings.

Click on the create credentials button to continue.

On the next screen, you will need to select ‘Web browser JavaScript’ in ‘Where you’ll be calling the API from’ field. After that click on the ‘User Data’ option.

To continue, click on the ‘What credentials do I need?’ button.

You will now be asked to provide a name for your OAuth client name. You can enter ‘WP Mail SMTP’ here.

Under JavaScript origins field, add your website’s domain name.

Next, you need to copy and paste the authorized redirect URL from WP Mail SMTP plugin settings.

Click on ‘Create client ID’ button to continue.

Next, you need to enter a name for OAuth consent screen. You can put the plugin’s name here.

Click on the continue button and developer console will show your client ID. You can copy it and paste it in WP Mail SMTP plugin’s settings page. However, you will still need client secret key.

Click on the Done button to move on.

You will now be taken to your project’s credentials page. You will see your recently created credentials listed there. Click on the edit button next to your credentials.

This will bring you to edit credentials page where you will be able to see your client secret key. You need to copy and paste the key in your plugin’s settings page.

Finish the setting on WP Dashboard

Return back to plugin’s settings page in your WordPress admin area. Now that you have both client ID and client secret keys, you need to click on the save settings button to continue.

The plugin will now store your settings and reload the page. After that you need to scroll down to the bottom of the settings page and click on the ‘Allow plugin to send emails using your Google account’ button.

This will take you to your account on Google and you will be asked to give the website permission to send emails on your behalf.

After that you will be redirected back to your website where you will see a success message.

You have successfully set up WordPress to use Gmail SMTP servers for sending emails using the OAuth protocol. You can now click on the ‘Email Test’ tab on plugin’s settings page to send a test email and see if everything is working fine.

Notify of
Inline Feedbacks
View all comments
- Advertisment -


How to whitelist website on AdBlocker?

Would love your thoughts, please comment.x