You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Outlook 365插件发送事件时拼写检查框重复弹出问题

Windows平台Outlook 365客户端拼写检查弹窗两次问题

在Windows平台的Outlook 365客户端中,点击发送按钮后拼写检查框会弹出两次:一次是点击发送按钮时触发,另一次是Outlook插件执行完event.completed()之后再次触发。

相关配置代码

manifest.xml

<Requirements>
  <Sets DefaultMinVersion="1.1">
    <Set Name="Mailbox" />
  </Sets>
</Requirements>

<Permissions>ReadWriteMailbox</Permissions>

<Rule xsi:type="RuleCollection" Mode="Or">
  <Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit" />
  <Rule xsi:type="ItemIs" ItemType="Appointment" FormType="Edit" />
</Rule>

<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
    <Description resid="residAppDescription" />
    <Requirements>
      <bt:Sets DefaultMinVersion="1.3">
        <bt:Set Name="Mailbox" />
      </bt:Sets>
    </Requirements>
    <Hosts>
      <Host xsi:type="MailHost">
        <DesktopFormFactor>
          <FunctionFile resid="residUILessFunctionFileUrl" />
          <ExtensionPoint xsi:type="Events">
            <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="validateBody" />
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Urls>
        <bt:Url id="residUILessFunctionFileUrl" DefaultValue="https://some.url/index.html" ></bt:Url>
      </bt:Urls>
    </Resources>

app.js

function validateBody(event) {
    Office.onReady().then(function() {
        var contextInfo = Office.context.diagnostics;
        if(contextInfo.platform == 'OfficeOnline'){
            // 执行在线环境逻辑
        } else{
            event.completed({ allowEvent: true });
        }
    });
}

问题原因

核心冲突来自同步执行的ItemSend事件与Outlook原生发送流程的交互:
当设置FunctionExecution="synchronous"时,Outlook会暂停原生发送流程,等待插件完成逻辑。但点击发送时,原生拼写检查已经触发一次;插件调用event.completed()后,Outlook会重新启动发送校验流程,导致拼写检查再次弹出。

解决方案

方案1:改为异步执行ItemSend事件(推荐)

将manifest.xml中的事件执行模式改为异步,避免Outlook重复触发校验流程:
修改manifest.xml中的Event配置:

<ExtensionPoint xsi:type="Events">
  <Event Type="ItemSend" FunctionExecution="async" FunctionName="validateBody" />
</ExtensionPoint>

同时可以优化app.js代码,使用async/await提升可读性:

async function validateBody(event) {
  await Office.onReady();
  const contextInfo = Office.context.diagnostics;
  if(contextInfo.platform === 'OfficeOnline'){
      // 执行在线环境专属逻辑
  } else{
      event.completed({ allowEvent: true });
  }
}

方案2:手动控制拼写检查(不推荐)

通过Outlook API手动触发拼写检查并禁用原生重复检查,但该方案兼容性差、实现复杂,不如异步方案简洁可靠,不建议采用。

内容的提问来源于stack exchange,提问作者Pedro Cordeiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:18:33