Outlook 邮件加载项 API 在 Web 和 Outlook 客户端中的工作方式不同

Outlook Mail add-in API works differently in the web and Outlook client

我需要使用 Outlook Mail add-in

向 outlook 主体添加一些内容

这是我的做法

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);
    });
}

来电

getBody(function (body) {
    setBody(body + " appended", function (r) {
        log(JSON.stringify(r));
    });
});

在 Outlook 网络中,这工作正常。但是在桌面客户端(Outlook 2016)中这不起作用。

这是从桌面版获取的回调结果

{"value":"","status":"succeeded"}

网页版的回调结果是这样得到的

{"value":null,"status":"succeeded"}

请帮忙。

找到了一个解决方案,我只是在 html 字符串的末尾附加了一个文本,这是一件很脏的事情。

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);
}

解析了 html 字符串并附加了我想要的标签。它得到了解决。 :)