Not Monitored
Tag not monitored by Microsoft.
43,569 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am using this library
<dependency>
<groupId>com.microsoft.graph</groupId>
<artifactId>microsoft-graph</artifactId>
<version>5.74.0</version>
</dependency>
in a spring boot app. I have successfully setup the client like this
@Bean
public GraphServiceClient graphServiceClient() {
try {
final ClientSecretCredential clientSecretCredential = new ClientSecretCredentialBuilder()
.clientId("...")
.clientSecret("...")
.tenantId("...")
.build();
final TokenCredentialAuthProvider tokenCredentialAuthProvider = new TokenCredentialAuthProvider(
List.of("https://graph.microsoft.com/.default"),
clientSecretCredential
);
return GraphServiceClient.builder()
.authenticationProvider(tokenCredentialAuthProvider)
.buildClient();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
and when I try to list users using
graphServiceClient.users()
UserCollectionPage usersPage = graphServiceClient.users()
.buildRequest()
.select("displayName,userPrincipalName,mail")
.get();
graphServiceClient.users()
everything works fine, so the access token and my graph client is configured fine.
When I try to send an email by using
graphServiceClient.users("...")
.sendMail(UserSendMailParameterSet
.newBuilder()
.withMessage(message)
.withSaveToSentItems(true)
.build())
.buildRequest()
.post();
I get this error that I can not recover from
com.microsoft.graph.http.GraphServiceException: Error code: Unable to parse error response message
Error message: Raw error:
POST https://graph.microsoft.com/v1.0/users/.../microsoft.graph.sendMail
SdkVersion : graph-java/v5.74.0
[...]
401 :
[...]
I have properly created the application and have added the required permissions.