3

How can we read mail at compose mode using office 365 JavaScript API?

Such as:

Office.initialize = function (reason) {
    var body = Office.context.mailbox.item.body;
};
MrPiao
  • 688
  • 5
  • 19
DevÁsith
  • 1,072
  • 12
  • 38

2 Answers2

6

Edit: Good news for anyone who is looking to achieve the same scenario - we do have an API that you can use to get the body of the message in compose mode. You can find out about the new API here: https://dev.outlook.com/reference/add-ins/Body.html#getAsync


Unfortunately, there is not a clean way to achieve this right now. However, we're working on APIs all the time and it's possible that this functionality is added in the future, so please stay tuned!

The closest workaround we can get right now is for you to tell the user to save the draft, get the EWS ID, and make an EWS request to get the body, but that's not very useful, is it? :)

MrPiao
  • 688
  • 5
  • 19
  • Have we got any workaround yet? I am trying to achieve the same thing. When composing the mail, I save it as a draft and take its itemId. But all the drafts show the same itemId. Any latest solution for this? – Shruti Dasgopal Mar 28 '16 at 07:24
  • 1
    I think this will work for you - https://dev.outlook.com/reference/add-ins/Body.html#getAsync – MrPiao Mar 28 '16 at 07:28
  • yes. thanks. Get the body in text format. But what about the itemId? Why is it the same for all the drafts? Any idea? I did according to, https://dev.outlook.com/reference/add-ins/Office.context.mailbox.item.html#itemId – Shruti Dasgopal Mar 28 '16 at 09:33
  • itemId property is for read mode only. It may return a value for compose mode but that operation is not supported. It seems that my initial workaround for you was quite faulty :( – MrPiao Mar 28 '16 at 16:05
0

The "get body content" funciton is an asynchronouse one, which means that you will need to pass some kind of a callback to it if you want to do something only after you had received the body content

Here is some code example :


var someCallback = function(bodyContent) {
      // do something with the content of the body
}

window.Office.context.mailbox.item.body.getAsync(
      "html",
      { asyncContext: {callback: someCallback} },
      (result) => {
        let content = result.value;
        asyncContext.callback(content); //this is where we are calling the callback
      }
)

More info here

Yos
  • 479
  • 1
  • 4
  • 14