Reputation: 1234
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;
};
Upvotes: 3
Views: 1597
Reputation: 469
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
Upvotes: 0
Reputation: 710
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? :)
Upvotes: 6