0
votes

I am trying to get the mime-content of the message with attachment, I am using 3.1.0, which has content method, I am using this method to get the mime-content(uses /$value), below is my request. Below is the reference documentation we are using.

https://docs.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0&tabs=java#example-4-get-mime-content

I am getting the response with code 200 and header as Content-Type: text/plain, body has nothing and body.contentLength() is coming as -1,

Yes, the mail has body and attachment in it.

Kindly help me if I am missing anything in the request/headers

Code for mime content for message: Request: https://graph.microsoft.com/v1.0/users/{Email Id}/messages/{message id}/$value

InputStream stream = graphClient.users("emailId")
       .messages(message.id)
       .content()
       .buildRequest()
       .get();
1
Have you tried testing it in Graph Explorer? Were you able to see the same issue? - Shiva Keshav Varma
Use the latest Graph SDK for Java and make the Graph API call - it works and i can get the MIME. Also test the above what @ShivaKeshavVarma recommended above. - Dev

1 Answers

0
votes

I found the answer on this, the following should allow you to represent the mime content at text.

final InputStream result = graphClient.me().messages("id").content().buildRequest().get();
final BufferedReader r = new BufferedReader(new InputStreamReader(result));
final StringBuilder content = new StringBuilder();
String line;

while ((line = r.readLine()) != null) {
   content.append(line).append('\n');
}

or

String text = CoreHttpProvider.streamToString(result);