【问题标题】:Outlook Mail add-in API works differently in the web and Outlook clientOutlook 邮件加载项 API 在 Web 和 Outlook 客户端中的工作方式不同
【发布时间】:2016-08-09 12:58:33
【问题描述】:

我需要使用 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"}

请帮忙。

【问题讨论】:

  • 您好,我刚刚在最新版本的 Outlook 2016 中尝试了此代码,但无法重现问题:Office.context.mailbox.item.body.getAsync("text", function (ar) { var body = ar.value; Office.context.mailbox.item.body.setAsync(body + " appended"); });你还能复制吗?您正在运行什么版本的 Outlook 2016?
  • 嗯..有区别。 ..getAsync("text",.. 不是我需要的。我需要 HTML 格式的邮件正文内容。

标签: outlook outlook-addin office365api office-js


【解决方案1】:

找到了一个解决方案,我只是将一个文本附加到一个 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 字符串并附加了我想要的标签。它得到了解决。 :)

【讨论】:

  • 如果您接受自己的答案,那么将来阅读本文的人会更清楚解决方案是什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-05-02
相关资源
最近更新 更多