Kranthi Kumar
Kranthi Kumar

Reputation: 61

Office.context.mailbox.item.body is not defined

I am developing Office Addin for outlook, I struct with the following, please kindly help.

Office.context.mailbox.item.body.getAsync() method is working fine in Office 365 , but when it comes to on premise exchange server 2013, it works in outlook client but not works in outlook web app. Minimum mailbox requirement set version is 1.3

issue

Upvotes: 0

Views: 1470

Answers (2)

user2773447
user2773447

Reputation: 1

You can retrieve the email body in Office Mailbox API version 1.1 and above by calling the Office.context.mailbox.getCallbackTokenAsync method and making an ajax call to an EWS server. The example Microsoft provides is located at this link:

https://learn.microsoft.com/en-us/javascript/api/outlook/office.mailbox?view=outlook-js-1.1#getcallbacktokenasync-callback--usercontext-

My working example:

Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, (result) => {
    var ewsId = Office.context.mailbox.item.itemId;
    var token = result.value;

    // var restId = Office.context.mailbox.convertToRestId(ewsId, Office.MailboxEnums.RestVersion.v2_0); this does not work on API version 1.1
    var restId = ewsId.replaceAll("/", "-").replaceAll("+", "_"); // Convert ewsId to restId
    var getMessageUrl = (Office.context.mailbox.restUrl || 'https://outlook.office365.com/api') + '/v2.0/me/messages/' + restId;
    var xhr = new XMLHttpRequest();
    xhr.open('GET', getMessageUrl);
    xhr.setRequestHeader('Prefer', 'outlook.body-content-type="html"') // for retrieving body as HTML
    xhr.setRequestHeader("Authorization", "Bearer " + token);
    xhr.onload = (e) => {
      var json = JSON.parse(xhr.responseText);
      var emailBody = json.Body.Content;
    }
    xhr.send();
  });

Upvotes: 0

Slava Ivanov
Slava Ivanov

Reputation: 6912

This is expected. Office.context.mailbox.item.body.getAsync minimum mailbox requirement version is wet to 1.3 level API. In same time according to "Understanding Outlook API requirement sets" the Outlook Web App (Exchange 2013 On-Premise) supports only 1.1 level API.

Upvotes: 1

Related Questions