Office 365 Rest API - Retrieving plain text Email

旧城冷巷雨未停 提交于 2019-12-02 05:54:03

问题


Is there currently anyway to with the Office 365 Rest APIs to retrieve the plain text part of an email message?

From the API documents it states that the 'Body' object contains the 'ContentType' field which can either be Text or HTML. https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#ItemBody

However whenever a multipart (HTML + plain text) message is retrieved the API only ever returns the HTML part as shown bellow:

{
  "@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"
}

Is there anyway of getting the plain text part. Possibly an OData query?

Many thanks, Nick


回答1:


No, this isn't possible. I can provide this feedback to our developers. Can you give me some background on why you need this ability? Not that I'm questioning, it's just helpful to have some context. :)




回答2:


Just wanted to give an update - you can now use the Microsoft Graph REST API to get messages returned in text format.

Note that this feature is currently in preview only. In general, we recommend using preview features only in non-production apps, as they may change without notice.

I listed an example below. The related documentation for Microsoft Graph - Get and List messages - will be updated within the next day.

This example shows how to use a Prefer: outlook.body-content-type="text" header to get the body and uniqueBody of the specified message in text format.

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

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

Here is the response. Note: The response includes a Preference-Applied: outlook.body-content-type header to acknowledge the Prefer: outlook.body-content-type request 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"
    }
}

Hope this helps!



来源:https://stackoverflow.com/questions/28436361/office-365-rest-api-retrieving-plain-text-email

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!