gpt4 book ai didi

c# - Microsoft Graph API 以 HTML 格式返回邮件正文

转载 作者:行者123 更新时间:2023-11-30 15:15:48 25 4
gpt4 key购买 nike

我想阅读我的电子邮件并将它们转换为 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"

requestMessage.Headers.Add("Prefer", "outlook.body-content-type='text'");

根据文档 https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/mail-rest-operations

编辑:

查看文档,这是客户端类代码: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;
}

关于c# - Microsoft Graph API 以 HTML 格式返回邮件正文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51491794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com