gpt4 book ai didi

email - Office 365 Rest API - 检索纯文本电子邮件

转载 作者:行者123 更新时间:2023-12-02 09:34:31 25 4
gpt4 key购买 nike

目前是否有使用 Office 365 Rest API 来检索电子邮件的纯文本部分?

从 API 文档中可以看出,“Body”对象包含“ContentType”字段,该字段可以是 TextHTMLhttps://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#ItemBody

但是,每当检索到多部分(HTML + 纯文本)消息时,API 只会返回 HTML 部分,如下所示:

{
"@odata.context": "",
"@odata.id": "",
"Id": "",
"Subject": "Test message",
"BodyPreview": "This is the body",
"Body": {
"ContentType": "HTML",
"Content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body style=\"word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;\">\r\n<div>This is the body</div>\r\n</body>\r\n</html>\r\n"
},
"UniqueBody": {
"ContentType": "HTML",
"Content": "<html><body><div>\r\n<div><font face=\"Calibri,sans-serif\" size=\"2\" color=\"black\"><span style=\"font-size:14px;\">\r\n<div>This is the body</div>\r\n</span></font></div>\r\n</div>\r\n</body></html>"
},
"HasAttachments": false,
"Sender": {
"EmailAddress": {
"Address": "",
"Name": "Nick Maher"
}
},
"DateTimeReceived": "2015-02-10T14:39:22Z",
"DateTimeSent": "2015-02-10T14:39:21Z"
}

有没有得到纯文本部分。可能是 OData 查询?

非常感谢,尼克

最佳答案

只是想提供一个更新 - 您现在可以使用 Microsoft Graph REST API 来获取以文本格式返回的消息。

请注意,此功能目前仅处于预览阶段。一般来说,我们建议您仅在非生产应用中使用预览功能,因为它们可能会更改,恕不另行通知。

我在下面列出了一个示例。 Microsoft Graph 的相关文档 - GetList消息 - 将在第二天更新。

本示例展示了如何使用 Prefer:outlook.body-content-type="text" header 以文本格式获取指定消息的正文和 uniqueBody。

Prefer: outlook.body-content-type="text"

GET https://graph.microsoft.com/beta/me/messages('AAMkAGI1AAAoZCfHAAA=')?$select=subject,body,bodyPreview,uniqueBody

这是回复。注意:响应包含一个 Preference-Applied:outlook.body-content-type header 以确认 Prefer:outlook.body-content-type 请求 header 。

HTTP/1.1 200 OK
Content-type: application/json
Preference-Applied: outlook.body-content-type="text"
Content-length: 1550

{
"@odata.context":"https://graph.microsoft.com/beta/$metadata#users('cd209b0b-3f83-4c35-82d2-d88a61820480')/messages(subject,body,bodyPreview,uniqueBody)/$entity",
"@odata.etag":"W/\"CQAAABYAAABmWdbhEgBXTophjCWt81m9AAAoZYj4\"",
"id":"AAMkAGI1AAAoZCfHAAA=",
"subject":"Welcome to our group!",
"bodyPreview":"Welcome to our group, Dana! Hope you will enjoy working with us !\r\n\r\nWould you like to choose a day for our orientation from the available times below:\r\n\r\n\r\nDate\r\n Time\r\n\r\nApril 14, 2017\r\n 1-3pm\r\n\r\nApril 21, 2017\r\n 10-12noon\r\n\r\n\r\n\r\nTh",
"body":{
"contentType":"text",
"content":"Welcome to our group, Dana! Hope you will enjoy working with us [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] !\r\n\r\nWould you like to choose a day for our orientation from the available times below:\r\n\r\n\r\nDate\r\n Time\r\n\r\nApril 14, 2017\r\n 1-3pm\r\n\r\nApril 21, 2017\r\n 10-12noon\r\n\r\n\r\n\r\nThanks!\r\n\r\n"
},
"uniqueBody":{
"contentType":"text",
"content":"Welcome to our group, Dana! Hope you will enjoy working with us [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] [\ud83d\ude0a] !\r\nWould you like to choose a day for our orientation from the available times below:\r\n\r\nDate\r\n Time\r\n\r\nApril 14, 2017\r\n 1-3pm\r\n\r\nApril 21, 2017\r\n 10-12noon\r\n\r\n\r\nThanks!\r\n"
}
}

希望这会有所帮助!

关于email - Office 365 Rest API - 检索纯文本电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28436361/

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