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

问题描述 投票:2回答:2

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

从API文档中可以看出,'Body'对象包含'ContentType'字段,该字段可以是Text或HTML。 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"
}

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

非常感谢,尼克

email office365 exchangewebservices plaintext
2个回答
1
投票

不,这是不可能的。我可以向开发人员提供此反馈。你能给我一些你需要这种能力的背景吗?不是我在质疑,有一些背景是有帮助的。 :)


3
投票

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

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

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

此示例显示如何使用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

这是回复。注意:响应包括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"
    }
}

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.