1

I'm trying to build custom notifications to users based on batch processes that execute in a scheduler. Success/Failure notifications etc.

I've taken a look at How to get access token using gmail api and I've been trying to get the REST call working.

I initially had used a service account to get an access token and based on GMail API - Can I send email using the Service Account? I cannot use a service account to impersonate a user for sending emails.

We reached out to Google support and got a person on chat who was unhelpful and she said we should use 2FA, which wont work because we want it fully automated.

This is what I'm trying to do in code:

strBuild.append("code=").append(**code**)
  .append("&client_id=").append(client_id)
  .append("&client_secret=").append(client_secret)
  .append("&redirect_uri=").append(redirect_uri)
  .append("&grant_type=").append(grant_type);

Where is the code coming from?

Another piece of code was retrieving an access token by sending a refresh token, now where is the refresh token coming from?

Also, Google's oAuth example uses opening a browser https://developers.google.com/gmail/api/quickstart/java

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
                .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
                .setAccessType("offline")
                .build();
        LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
        Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");

Which defeats the purpose of automation. I've looked at other posts and there are no example of full automation without authorizing to get a code.

Is this even possible without human intervention using REST for Gmail?

Adrian
  • 59
  • 6
  • I have the same requirement. Could any one please help? @Adrian did you get the solution for this? – Hari Oct 29 '22 at 18:46

0 Answers0