Just add the following line to make it work
attachments.oDataType = "#microsoft.graph.fileAttachment";
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 the sample code to send a mail with a file attachement, and it appears there is a bug in the library.
I'm using graph-java v5.68.0
Sample: [https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java ](https://learn.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=java
)See Example 3 . Create a message with a file attachment and send the message
When i run this I get the error
com.microsoft.graph.http.GraphServiceException: Error code: RequestBodyRead
Error message: The property 'contentBytes' does not exist on type 'microsoft.graph.attachment'. Make sure to only use property names that are defined by the type or mark the type as open type.
POST https://graph.microsoft.com/v1.0/users/******@fmr.com/microsoft.graph.sendMail
SdkVersion : graph-java/v5.68.0
[...]
400 : Bad Request
[...]
It appears to be the same issue as asked here https://learn.microsoft.com/en-us/answers/questions/1355625/graph-api-sendmail-the-property-contentbytes-does
Debugging the code, I see that the oDataType is null for the attachemnt. Hardcoding this value to fileAttachment fixes the issue.
Just add the following line to make it work
attachments.oDataType = "#microsoft.graph.fileAttachment";