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

Nic*_*her 2 email plaintext exchangewebservices office365

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

从 API 文档中可以看出,'Body' 对象包含可以是TextHTML的 'ContentType' 字段。https://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"
}
Run Code Online (Sandbox Code Playgroud)

无论如何都可以获得纯文本部分。可能是 OData 查询?

非常感谢,尼克

小智 5

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

请注意,此功能目前仅处于预览状态。通常,我们建议仅在非生产应用程序中使用预览功能,因为它们可能会更改,恕不另行通知。

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

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

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

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

这是回应。注意:响应包括 Preference-Applied: outlook.body-content-type 标头以确认 Prefer: outlook.body-content-type 请求标头。

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"
    }
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!