Getting "The tenant for tenant guid {id} does not exist when using microsoft Graph Client to send email in Java

Learning Developer 0 Reputation points
2024-02-04T18:05:50.2766667+00:00

We are creating a app where we can provide email services to user and user can schedule the email sending as well. For this we created a app on Microsoft Azure, Set up the permissions on App and added the users. I am writing JAVA POC for this using msal4j and microsoft graph api. This is what I am doing.

IAuthenticationProvider iAuthProvider = new TokenCredentialAuthProvider(clientSecretCredential());
        
GraphServiceClient<Request> graphClient = GraphServiceClient
                .<Request>builder()
                .authenticationProvider(iAuthProvider)
                .buildClient();

//Creating msg body for Email
Message message = new Message();
graphClient.users(senderUserEmail).sendMail(UserSendMailParameterSet
		.newBuilder()
		.withMessage(message)
		.withSaveToSentItems(saveToSentItems)
		.build()).buildRequest()
	.post();

I am using clientCredentialAuth for getting token I do have all the values ClientID, ClientSecret, TenantId. Method clientSecretCredential() is defined as below.

    private ClientSecretCredential clientSecretCredential() {
        return new ClientSecretCredentialBuilder()
          .clientId(clientId)
          .tenantId(tenantId)
          .clientSecret(clientSecret)
          .build();
        }

but when I run the code I get following error.

{
  "error": {
    "code": "OrganizationFromTenantGuidNotFound",
    "message": "The tenant for tenant guid {tenantId} does not exist.",
    "innerError": {
      "errorUrl": "https://aka.ms/autherrors#error-InvalidTenant",
      "date": "2024-02-04T11:18:24"
    }
  }
}

Not sure what I am doing wrong here. I explored lot of solution but not getting solution of the error.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,988 questions
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AsithwMSFT 1,520 Reputation points Microsoft External Staff
    2024-02-04T20:17:22.53+00:00

    Learning Developer
    value that you added to tenant ID may be incorrect or invalid. Have you double checked the tenant ID?

    you can verify this value using azure or admin center

    How to find your Microsoft Entra tenant ID


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.