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

关于Office.context.mailbox.item.addFileAttachmentAsync紧跟saveAsync调用时行为不一致的问题问询

问题:Outlook Add-in 中 addFileAttachmentAsync 与 saveAsync 连续调用引发的行为不一致

在Outlook插件开发过程中,异步API的调用顺序很容易引发奇怪的问题,这次遇到的情况就是:如果在调用 Office.context.mailbox.item.addFileAttachmentAsync 后立即执行 item.saveAsync,会出现明显的行为不一致,具体细节如下:

复现代码(Script Lab 中测试)

以下是能稳定复现该问题的代码:

$("#run").click(run);
let callbackCount = 0;

function run() {
  for(let i=0; i<10; i++) {
    Office.context.mailbox.item.addFileAttachmentAsync(
      "https://ow2.res.office365.com/owalanding/2021.4.9.04/images/outlook-icon.jpg", 
      "test.jpg", 
      () => { console.log(callbackCount++)}
    );
    // 注释掉这行代码后,所有附件都能正常添加,问题消失
    Office.context.mailbox.item.saveAsync((res) => { console.log(res) });
  }
}

异常表现

  • 执行代码后,撰写面板中仅能看到2-3个附件被添加,远达不到循环预期的10个
  • saveAsync 的回调函数仅触发1次,而非循环设定的10次
  • 一旦注释掉循环内的 saveAsync 调用,所有10个附件都会正常出现在撰写面板中

环境信息

  • 问题复现环境:New Outlook for Mac v16.52 (21080101)、macOS Big Sur 11.5.1
  • 无问题环境:旧版Outlook for Mac,附件会按预期被添加10次

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 03:37:50