Office 365 Rest API - 检索纯文本电子邮件
Office 365 Rest API - Retrieving plain text Email
目前是否可以使用 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 只会 returns 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 获取以文本格式返回的消息。
请注意,此功能目前仅处于预览阶段。通常,我们建议仅在 non-production 个应用中使用预览功能,因为它们可能会更改,恕不另行通知。
我在下面列出了一个例子。 Microsoft Graph 的相关文档 - Get and List 消息 - 将在第二天更新。
此示例说明如何使用 Prefer: outlook.body-content-type="text" header 以文本格式获取指定消息的 body 和 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"
}
}
希望对您有所帮助!
目前是否可以使用 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 只会 returns 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 获取以文本格式返回的消息。
请注意,此功能目前仅处于预览阶段。通常,我们建议仅在 non-production 个应用中使用预览功能,因为它们可能会更改,恕不另行通知。
我在下面列出了一个例子。 Microsoft Graph 的相关文档 - Get and List 消息 - 将在第二天更新。
此示例说明如何使用 Prefer: outlook.body-content-type="text" header 以文本格式获取指定消息的 body 和 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"
}
}
希望对您有所帮助!