I want to read my email messages and transform them into json. I am using Microsoft Graph API to query the office 365 mail box like this
GraphServiceClient client = new GraphServiceClient(
new DelegateAuthenticationProvider (
(requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", token);
return Task.FromResult(0);
}
)
);
var mailResults = await client.Me.MailFolders.Inbox.Messages.Request()
.OrderBy("receivedDateTime DESC")
.Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body})
.Top(100)
.GetAsync();
I followed this tutorial to get to this stage. But my message body is returned as html instead of text. Is there a way I can specify the message.body to return text or even json instead of HTML?
Don't you have to set the HTTP request header:
As per the documentation https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/mail-rest-operations
Edit:
View the documentation, this is the client class code: https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Requests/Generated/GraphServiceClient.cs
Here is an example from the link you're following: