【问题标题】:Outlook add in On-Send event is firingOutlook 添加 On-Send 事件正在触发
【发布时间】:2020-06-03 00:31:56
【问题描述】:

我试图获得一个简单的函数,使用 on-send 函数将一些数据附加到邮件正文。

在我的清单文件中,我设置了扩展点

<ExtensionPoint xsi:type="Events">
    <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="setItemBody" />
</ExtensionPoint>

我的 javascript 取自 https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/outlook-on-send-addins?tabs=windows

function validateBody(event) {
    console.log('validateBody');
    item.body.getAsync("html", { asyncContext: event }, checkBodyOnlyOnSendCallBack);
}

// <param name="asyncResult">MessageSend event passed from the calling function.</param>
function checkBodyOnlyOnSendCallBack(asyncResult) {
    var listOfBlockedWords = new Array("blockedword", "blockedword1", "blockedword2");
    var wordExpression = listOfBlockedWords.join('|');

    // \b to perform a "whole words only" search using a regular expression in the form of \bword\b.
    // i to perform case-insensitive search.
    var regexCheck = new RegExp('\\b(' + wordExpression + ')\\b', 'i');
    var checkBody = regexCheck.test(asyncResult.value);

    if (checkBody) {
        mailboxItem.notificationMessages.addAsync('NoSend', { type: 'errorMessage', message: 'Blocked words have been found in the body of this email. Please remove them.' });
        // Block send.
        asyncResult.asyncContext.completed({ allowEvent: false });
    }

    // Allow send.
    asyncResult.asyncContext.completed({ allowEvent: true });
}

但是当我在电子邮件上点击发送时,我只是不断收到“插件已阻止发送此项目。”

在浏览器调试器中我看不到它已经在 validateBody 事件中写出了 console.log。

有人知道我做错了什么吗?

【问题讨论】:

    标签: outlook office-js outlook-addin


    【解决方案1】:

    作为对此的更新,正如我现在已经解决的那样,这是由于被调用函数(在我的情况下为 setItemBody)驻留在 Function.js 中的位置(或曾经设置为函数文件的位置)

    ItemSend 调用的方法必须位于根目录,甚至在 Office.initialize 函数之前。这至少为我解决了这个问题,因为我通过阅读这篇文章找到了它https://theofficecontext.com/2017/06/12/the-most-anticipated-officejs-feature-is-here/

    【讨论】:

      猜你喜欢
      • 2017-08-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-11
      • 2014-04-20
      • 2012-06-24
      • 1970-01-01
      相关资源
      最近更新 更多