【问题标题】:Outlook add-in On send feature not calling functionOutlook 加载项发送功能不调用功能
【发布时间】:2021-10-30 07:36:32
【问题描述】:

我一直在 Chromium Edge 上测试 Outlook 加载项 On-send 功能。但由于某种原因,它从不调用函数 validateBody。

command.js

let mailboxItem;
    Office.initialize = function (reason) {
      mailboxItem = Office.context.mailbox.item;
    };
    // Determine whether the body contains a specific set of blocked words. If it contains the blocked words, block email from being sent. Otherwise allow sending.
    // <param name="asyncResult">ItemSend event passed from the calling function.</param>
    async function checkBodyOnlyOnSendCallBack(asyncResult) {
      const listOfBlockedWords = new Array("dammit", "porra", "caralho");
      const 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.
      const regexCheck = new RegExp("\\b(" + wordExpression + ")\\b", "i");
      const 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 });
    }
    // Entry point for Contoso Message Body Checker add-in before send is allowed.
    // <param name="event">ItemSend event is automatically passed by on-send code to the function specified in the manifest.</param>
    function validateBody(event) {
      mailboxItem.body.getAsync("html", { asyncContext: event }, checkBodyOnlyOnSendCallBack);
    }

manifest.xml

    <FunctionFile resid="Commands.Url" />
                <ExtensionPoint xsi:type="Events">
                  <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="validateBody" />
                </ExtensionPoint>
...
<bt:Urls>
          <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
        </bt:Urls>

Office.initialize 总是被调用,但从不 validateBody。但结果我只是得到消息: 很抱歉,我们无法访问测试。确保您有网络连接。如果问题仍然存在,请稍后再试。加载项测试已阻止发送此项目。

我该如何解决这个问题?

编辑:这是 Outlook 窗口上的错误消息

Outlook 版本: Microsoft® Outlook® 2019 MSO (16.0.14326.20164) 64 位 这是 Outlook web 上的错误消息

【问题讨论】:

  • 您在运行帖子中提到的示例加载项时有任何问题吗?
  • 说实话。结果和我做的一样。 On send 加载项是否需要某种类型的特殊配置?因为我的安装方式与我所做的其他方式相同。我通过清单安装加载项,但是当我尝试发送消息时,它会重复相同的行为
  • @Eugene Astafiev 我相信我理解我的错误我正在使用我的免费 Outlook 帐户 live.com 作为测试环境,所以我不能使用 On send,因为我的电子邮件不允许这样做,对吗?
  • 您使用的是什么 Outlook 客户端(Mac、Win32、OWA)? OnSend 支持的客户端和平台列表可在此处找到:docs.microsoft.com/en-us/office/dev/add-ins/outlook/…
  • 我正在使用 OWA。我在 Windows 上尝试过,但又遇到了一个错误,但又是一个不同的错误:... 无法完成

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


【解决方案1】:

很抱歉,我们无法访问 Test。确保您有网络连接。如果问题仍然存在,请稍后再试。加载项测试已阻止发送此项目。

这是一个很好的指标,表明 OfficeJS 运行时无法找到清单文件中指定的函数。确保 Web 应用程序在清单 URL 中指定的地址上运行,并且该函数可公开访问。

默认情况下,如果未找到回调(无法到达该函数),则阻止发送操作并向用户显示通知消息。

我建议在更改插件中的任何内容之前先使用the sample project available on GitHub,或者创建自己的并修改它。

【讨论】:

    猜你喜欢
    • 2018-05-07
    • 2011-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    相关资源
    最近更新 更多