Hello,

In this article, I will tell you how to use Gmail API. I am mostly using Gmail API in automation project to validate emails sent through my company’s system. We can login to Gmail and check the emails from UI but it takes a lot of time and it’s not a good practice to test Gmail in production. So we are using Gmail API. Let’s start

 

Enable Gmail API

First step is to enable the Google APIs and Service. So you need to go https://console.developers.google.com to activate the API access of the email that you will use in your project. Click ENABLE APIS AND SERVICES. It will take you to the search page.

There, you need to search for GMAIL.

When you select the GMAIL API, you need to push the ENABLE button. It’s so easy right!

Configure Gmail Consent Screen

Now you need to create credentials that you’ll use in the project. Those credentials will give you access to any Gmail services. Select CREATE CREDENTIALS button

 

In the next screen, you have to select the OAuth consent screen and select External. If you choose Internal, your app will require a verification. Select External and click CREATE button.

Give a name to your application. I added “SWTESTACADEMY” as my project name. There are some already defined Scopes for you. In case you need to do more with Gmail API, just add whatever suite your need. For this tutorial, default ones are ok.

Congrats, you just configured the consent screen that you will need once in the project.

 

Create GMAIL Credentials

Now, navigate to Credentials page once again. Select CREATE CREDENTIALS on the top menu. Then select OAuth client ID sub menu.