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();

我按照本教程进入了这个阶段。但是我的消息正文返回为 html 而不是文本。有没有办法可以指定 message.body 返回文本甚至 json 而不是 HTML?


慕码人2483693
浏览 216回答 2
2回答

繁星点点滴滴

使用 GraphServiceClient,.Header("Prefer", "outlook.body-content-type='text'")作为请求方法链的一部分调用:var mailResults = await client.Me.MailFolders.Inbox.Messages                                .Request()                                .Header("Prefer", "outlook.body-content-type='text'")                                .OrderBy("receivedDateTime DESC")                                .Select(m => new { m.Subject, m.ReceivedDateTime, m.From, m.Body})                                .Top(100)                                .GetAsync();
打开App,查看更多内容
随时随地看视频慕课网APP