Error on sending graph api mail with upload session

scenterportal 6 Reputation points
2021-09-22T23:51:04.59+00:00

Hi, the java application that I have to maintain
uses MS Graph API to sending mail.(java graph sdk version is 1.9.0)
But recently I noticed that It is not able to send the email with the file attachment which is more than 3MB.

After searching the internet, I noticed it needs to make uploadsession if I want to attach more than 3MB attachment
https://learn.microsoft.com/en-us/graph/api/attachment-createuploadsession?view=graph-rest-1.0&tabs=java

So I changed my code with following reference.
(1. save mail as a draft status, 2. make uploadsession, 3. upload the big size file to the uploadsession, 4. sending mail on the draft box)
https://stackoverflow.com/questions/64262929/email-with-multiple-attachments-using-graph-api-4-mb

But after changing code, I got error below

com.microsoft.graph.core.ClientException: Error code: InvalidAudienceForResource
Error message: The audience claim value is invalid for current resource. Audience claim is 'https://graph.microsoft.com/', request url is 'https://outlook.office.com/api/gv1.0/users(...

It seems that my GraphServiceClient uses access token from scope "https://graph.microsoft.com/.default" and this not working with uploadsession for big size attachment.
Also My java application uses msal client to get access token
https://github.com/Azure-Samples/ms-identity-java-daemon/blob/master/msal-client-credential-certificate/README.md

In this case, I don't know what I have to do to solve this problem.
Please help me

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,576 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,536 questions
0 comments No comments
{count} vote

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.