Send email from MY gmail account using OAuth2 and nodemailer

I want to send emails from my gmail address through my own server. I am using nodemailer and the account credentials are jagged and often the time does not work and results in this thread

I have implemented everything on this thread many times and still it is flaky and also I know OAuth2 is the way to go .

I have a project with cliendID and clientSecret in google developer console as you can see:

enter image description here

But how do I get the access token WITHOUT interacting with the browser?

It seems to me that there is nothing trivial here ...

I have looked through all the Google tutorials and docs I could find about OAuth2, tokens and APIs, but all the tutorials go through the browser at one point.

+2


source to share


2 answers


Go to OAuth Playground , click the screw in the top right corner, check Use your own OAuth credentials

and enter clientID

and clientSecret

.



Then select the areas Gmail API v1

you want from the list on the left and follow the steps outlined and you will get access_token

and refresh_token

.

+3


source


Google Oauth2 Virtually all Oauth2 implementations I know of require the user to provide access to the application through a web browser.

There is an alternative type called service accounts, which is more like oauth1 service accounts . You can share the service account with your Google Drive by sharing folders and files with the service account just like any other user. Because they are pre-authorized, no browser window opens with service accounts.



You can only have Gmail user accounts if you have a Google Gsuite domain account. An administrator can log in and grant service account access to the Gmail account in question. Perform G Suite Domain Ownership

If it's a regular user Gmail account, you can't use the service account. You will need to use Oauth2 for the popup request and save the refresh token so you can access it later.

0


source







All Articles