使用office js将隐藏内容附加到outlook中的会议正文中

时间:2018-04-06 12:08:06

标签: outlook-addin office-js outlook-web-addins

使用我的Outlook加载项我需要向会议主体添加一些隐藏数据(一些元数据)。我尝试将display:none样式添加到html元素但没有运气。有没有办法实现这个目标? 下面是我设置正文内容的代码

  function addWorkspaceToItemBody(textToAppend) {
        var d = $q.defer();
          var item = Office.context.mailbox.item;
        item.body.getTypeAsync(
            function (result) {
                if (result.status == Office.AsyncResultStatus.Failed){
                    write(result.error.message);
                }
                else {
                    // Successfully got the type of item body.
                    // Set data of the appropriate type in body.
                    if (result.value == Office.MailboxEnums.BodyType.Html) {
                        // Body is of HTML type.
                        // Specify HTML in the coercionType parameter
                        // of setSelectedDataAsync.
                        item.body.setSelectedDataAsync(
                            '<p style="display:none">'+textToAppend+'<\p>',
                            { coercionType: Office.CoercionType.Html, 
                            asyncContext: { var3: 1, var4: 2 } },
                            function (asyncResult) {
                                if (asyncResult.status == 
                                    Office.AsyncResultStatus.Failed){
                                    d.reject(asyncResult.error.message);
                                }
                                else {
                                    d.resolve(asyncResult)
                                    // Successfully set data in item body.
                                    // Do whatever appropriate for your scenario,
                                    // using the arguments var3 and var4 as applicable.
                                }
                            });
                    }
                    else {
                        // Body is of text type. 
                        item.body.setSelectedDataAsync(
                            "",
                            { coercionType: Office.CoercionType.Text, 
                                asyncContext: { var3: 1, var4: 2 } },
                            function (asyncResult) {
                                if (asyncResult.status == 
                                    Office.AsyncResultStatus.Failed){
                                    d.reject(asyncResult.error.message);
                                }
                                else {
                                    d.resolve(asyncResult)
                                    // Successfully set data in item body.
                                    // Do whatever appropriate for your scenario,
                                    // using the arguments var3 and var4 as applicable.
                                }
                             });
                    }
                }
            });
            return d.promise;
    }

1 个答案:

答案 0 :(得分:0)

下面是使用以下代码插入隐藏内容的示例。该内容隐藏在Outlook 2016,OWA和Outlook for Android中。如果内容在其他电子邮件客户端中被视为纯文本,则可能仍会显示。

var content = 
"<!--[if !mso 9]><!-->"+
'<div class="hidden" style="display:none;max-height:0px;overflow:hidden;">'+
"CONTENT HERE THAT YOU WANT TO HIDE"+
"</div>"+
"<!--<![endif]-->";

Office.context.mailbox.item.body.setSelectedDataAsync("Hello World! " + content, function (asyncResult) {
  if (asyncResult.status == "failed") {
    console.log("Action failed with error: " + asyncResult.error.message);
  }
});

String + Format parsing