C#-Microsoft Graph API将邮件正文作为HTML返回
作者:互联网
我想阅读我的电子邮件并将其转换为json.我正在使用Microsoft Graph API这样查询Office 365邮箱
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();
我按照this教程进行了学习.但是我的邮件正文以html而不是文本形式返回.有没有一种方法可以指定message.body返回文本甚至json而不是HTML?
解决方法:
您不必设置HTTP请求标头:
Prefer: outlook.body-content-type=”text”
编辑:
查看文档,这是客户端类代码:https://github.com/microsoftgraph/msgraph-sdk-dotnet/blob/dev/src/Microsoft.Graph/Requests/Generated/GraphServiceClient.cs
这是您关注的链接中的一个示例:
private static GraphServiceClient GetClient(string accessToken, IHttpProvider provider = null)
{
var delegateAuthProvider = new DelegateAuthenticationProvider((requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
return Task.FromResult(0);
});
var graphClient = new GraphServiceClient(delegateAuthProvider, provider ?? HttpProvider);
return graphClient;
}
标签:microsoft-graph,office365,office365api,c,microsoft-graph-security 来源: https://codeday.me/bug/20191025/1925675.html