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

如何在点击Outlook发送按钮或邮件发送时调用自定义Outlook Add-in

Outlook插件触发方案:发送时调用 + 发送完成后打开

一、点击发送按钮时调用插件

1. 修改插件清单文件

  • 确保权限配置为ReadWriteMailbox:
    <Permissions>ReadWriteMailbox</Permissions>
    
  • 在<VersionOverrides>节点下的<Events>扩展点中,绑定ItemSend事件:
    <ExtensionPoint xsi:type="Events">
      <Event Type="ItemSend" FunctionName="handleItemSend" />
    </ExtensionPoint>
    

2. 编写发送事件处理逻辑

在插件的JS文件中添加以下代码,可在此触发插件功能(如打开任务窗格、执行校验等):

function handleItemSend(event) {
  // 打开插件任务窗格
  Office.context.ui.displayDialogAsync(
    window.location.origin + "/taskpane.html",
    { height: 50, width: 50 },
    (asyncResult) => {
      if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
        console.log("插件已启动");
      }
      // 允许邮件发送,若需阻止则设为false
      event.completed({ allowEvent: true });
    }
  );
}

二、邮件发送完成后打开插件

1. 修改插件清单文件

  • 同样确保权限为ReadWriteMailbox,在<Events>扩展点中添加已发送文件夹的ItemAdded事件绑定:
    <ExtensionPoint xsi:type="Events">
      <Event Type="ItemAdded" FunctionName="handleSentItemAdded" />
      <SupportedItems>
        <Item Type="Message" />
      </SupportedItems>
      <Folders>
        <DefaultFolder Name="SentItems" />
      </Folders>
    </ExtensionPoint>
    

2. 编写发送完成事件处理逻辑

添加处理函数,监听已发送文件夹的新邮件并打开插件:

function handleSentItemAdded(event) {
  Office.context.mailbox.item.loadPropertiesAsync(["subject"], (asyncResult) => {
    if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
      console.log("检测到新发送邮件:" + asyncResult.value.subject);
      // 打开插件任务窗格
      Office.context.ui.displayDialogAsync(
        window.location.origin + "/taskpane.html",
        { height: 50, width: 50 },
        (dialogResult) => {
          if (dialogResult.status === Office.AsyncResultStatus.Succeeded) {
            console.log("发送完成后插件已打开");
          }
        }
      );
    }
  });
}

关键注意事项

  • 该方案支持Outlook桌面端(Windows/Mac)及网页版的兼容版本,需确保插件使用的Office.js版本符合要求。
  • 测试时需将插件侧载到Outlook中,可通过Yeoman生成器的流程完成侧载配置。

内容的提问来源于stack exchange,提问作者R. Mohammad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 22:02:49