0

In JavaScript file I'm using REST to communicate with Office 365 APIs for mail, I'm getting the messages but nothing about the message's ContentBytes, since I need to save the message (email) in file with eml extension.

The code is:

 var messageEndpoint = "https://outlook.office.com/api/v2.0/me/messages/" + mailId + "/attachments";
    $.ajax({
        type: "GET",
        url: messageEndpoint,
        headers: {
            'Authorization': 'Bearer ' + outlookToken,
        },
        success: function (messageResponse) {  }

"messageResponse" has the message properties( like: from, to, body, etc.) but not the Content Bytes.

Anybody has idea how to convert the Office 365 mail messages REST response to byte [] then to save it in file ?

Thanks

Raed Alahmad
  • 985
  • 1
  • 7
  • 7
  • Did you read the complete documentation at https://msdn.microsoft.com/office/office365/APi/mail-rest-operations#Getmessages ? The content is a string (same as byte[]) at messageResponse.Body.Content. – Tserkov Feb 06 '16 at 23:10
  • I read it couple of times actually. Body.Content is just the email body, I'm looking to save the whole email (from: To: ,, etc.) as eml file – Raed Alahmad Feb 07 '16 at 04:43
  • You can create an EML file yourself if you have the other components, as the format is quite simple. See this answer: http://stackoverflow.com/questions/27951843/use-javascript-to-create-an-html-email-in-microsoft-outlook – Tserkov Feb 11 '16 at 00:04

1 Answers1

1

There is currently no property that exposes the entire MIME stream. You'd have to use Exchange Web Services to do this. You can also file a suggestion against the API at http://officespdev.uservoice.com/.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • That is right, it works well with EWS but unfortunately it is hard limited to 1MB response for JavaScript API call, and most likely this is not enough for email even without attachment. Thanks for your advice – Raed Alahmad Feb 08 '16 at 21:42