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

Email Office 365 Rest API-检索纯文本电子邮件,email,office365,exchangewebservices,plaintext,Email,Office365,Exchangewebservices,Plaintext,目前是否仍有其他方法可以使用Office 365 Rest API检索电子邮件的纯文本部分 从API文档中可以看出,“Body”对象包含“ContentType”字段,该字段可以是文本或HTML 但是,每当检索到多部分(HTML+纯文本)消息时,API仅返回HTML部分,如下所示: { "@odata.context": "", "@odata.id": "", "Id": "", "Subject": "Test message", "BodyPreview": "This

目前是否仍有其他方法可以使用Office 365 Rest API检索电子邮件的纯文本部分

从API文档中可以看出,“Body”对象包含“ContentType”字段,该字段可以是文本或HTML

但是,每当检索到多部分(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.context”:”,
“@odata.id”:”,
“Id”:“,
“主题”:“测试消息”,
“身体预览”:“这就是身体”,
“正文”:{
“内容类型”:“HTML”,
“内容”:“\r\n\r\n\r\n\r\n\r\n这是正文\r\n\r\n\r\n”
},
“唯一实体”:{
“内容类型”:“HTML”,
“内容”:“\r\n\r\n这是正文\r\n\r\n\r\n”
},
“HasAttachments”:假,
“发件人”:{
“电子邮件地址”:{
“地址”:“地址”,
“姓名”:“尼克·梅尔”
}
},
“DateTimeReceived”:“2015-02-10T14:39:22Z”,
“DateTimeSent”:“2015-02-10T14:39:21Z”
}
有没有办法得到纯文本部分。可能是OData查询


非常感谢,尼克不,这是不可能的。我可以向我们的开发人员提供此反馈。你能告诉我你为什么需要这种能力吗?我不是在质疑,只是有一些背景知识是有帮助的。:)

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

请注意,此功能当前仅处于预览状态。一般来说,我们建议仅在非生产应用程序中使用预览功能,因为它们可能会在未经通知的情况下更改

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

此示例显示如何使用prefere:outlook.body content type=“text”标题以文本格式获取指定邮件的正文和唯一正文

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

GET https://graph.microsoft.com/beta/me/messages('AAMkAGI1AAAoZCfHAAA=')?$select=subject,body,bodyPreview,uniqueBody
以下是回应。注意:响应包括一个应用的首选项:outlook.body-content-type标头,以确认首选项: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"
    }
}

希望这有帮助

嗨,杰森,我想去掉任何引用的回复文本。使用纯文本更容易,因为引用的文本行几乎总是以“>”字符开头。我希望使用这个库:。我认为对于多部分电子邮件,最好返回一个“Body”字段列表,每个部分都作为自己的对象。我会在反馈中包含这些信息。嗨,Jason,你知道在将此功能添加到O365 API方面是否有任何进展吗?当使用API来处理和解析传入邮件的文本时,这将非常有用,因为当前如果邮件是HTML格式的,则很难仅从电子邮件中提取回复文本而忽略其他所有内容。谢谢。据我所知没有进展。你可以为它添加一个建议,这样人们就可以投票支持它:)谢谢你指出瓦迪姆。Angelgolfer下面的答案应该是现在可以接受的答案。我知道,旧线程,但是否有可能扩展此参数,以便唯一的正文可以选择作为纯文本返回,而将整个正文保留为html?这在我的生产环境中很有用,因为我们目前让EWS以纯文本形式返回唯一的正文,以便在一个地方显示,但电子邮件的完整html包括在其他地方引用。@Angelgolfer ms您能告诉我如何将此
首选:outlook.body content type=“text”
添加到我的标题中吗?我正在使用节点outlook