Hi @Ankur Shah ,
You can use Get attachment Microsoft Graph API to read the properties, relationships, or raw contents of an attachment that is attached to a message in Outlook/Exchange Online.
Microsoft Graph Java SDK method to get the raw contents of an attachment that is attached to message :
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
InputStream stream = graphClient.me().messages("Message-ID").attachments("Attachment-ID").content()
.buildRequest()
.get();
Example :
However as mentioned in this Github issue, it seems there is some known issue with content() method in Microsoft Graph Java SDK and the below alternarive suggestion/workarround was provided in this GitHub issue post. Please refer the same for more information on this.
final InputStream result = new FileAttachmentStreamRequestBuilder(graphClient.me().messages("id").attachments("id").buildRequest().getRequestUrl().toString() + "/$value", graphClient, null).buildRequest().get();
You can also refer the below addtional links on this Github Issue for more information:
https://github.com/microsoftgraph/msgraph-sdk-java/issues/733
https://github.com/microsoftgraph/msgraph-sdk-java/issues/733#issuecomment-851431912
https://github.com/microsoftgraph/msgraph-sdk-java/issues/733#issuecomment-851795147
https://github.com/microsoftgraph/msgraph-sdk-serviceissues/issues/92
Since this is a Microsoft Java SDK issue, I would advise you to raise an issue with GitHub SDKs support team for any questions on this.
Hope this helps.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have any further questions about this answer, please click "Comment".