Reputation: 582
I need to append something to the body of outlook using a Outlook Mail add-in
Here is how i do it
function getBody(cb) {
Office.context.mailbox.item.body.getAsync(
"html",
{ asyncContext: "This is passed to the callback" },
function (result) {
cb(result.value);
});
}
function setBody(content, cb) {
Office.context.mailbox.item.body.setAsync(
content,
{ coercionType: Office.CoercionType.Html },
function (result2) {
cb(result2);
});
}
Here is the call
getBody(function (body) {
setBody(body + " appended", function (r) {
log(JSON.stringify(r));
});
});
In the outlook web this works fine. But in the desktop client (Outlook 2016) this does not work.
This is what get for the callback result from the desktop version
{"value":"","status":"succeeded"}
This is what get for the callback result from the web version
{"value":null,"status":"succeeded"}
Please Help.
Upvotes: 1
Views: 441
Reputation: 582
Found a solution, I was just appending a text to the end of a html string that is a dirty thing to do.
function FormatBody(bodyContent, extraContent, callback) {
var domParser = new DOMParser();
var parsedHtml = domParser.parseFromString(bodyContent, "text/html");
$("body", parsedHtml).append("<div>" + extraContent + "</div>");
var changedString = (new XMLSerializer()).serializeToString(parsedHtml);
callback(changedString);
}
Parsed the html string and appended the tag i wanted. It got solved. :)
Upvotes: 1