【问题标题】:Attaching .msg File Using addFileAttachmentAsync Fails使用 addFileAttachmentAsync 附加 .msg 文件失败
【发布时间】:2020-11-10 07:26:54
【问题描述】:

我正在开展一个项目,我们试图通过 React/TypeScript 中创建的 Outlook 插件将各种文档附加到电子邮件草稿中。基本上,我们有以下代码 sn-p 用于将文件作为附件添加到当前电子邮件草稿中:

     public attachFile(fileUrl: string, filename: string): Promise<Office.AsyncResult<any>> {
        return new Promise(async (resolve, reject) => {
            (Office.context.mailbox.item as any).addFileAttachmentAsync(
                fileUrl,
                filename,
                { asyncContext: null },
                (attachResult: Office.AsyncResult<any>) => {
                    resolve(attachResult);
                }
            );
        });
    }

现在通常,当这个函数被触发时,它看起来像这样:

const outlookApp = this.officeApp as OutlookOfficeApp;
const attachResult = await outlookApp.attachFile(attachUrl, fileName);

在一个可行的示例中,文件名是 Document 1.docx - 但对于 .msg 文件,此函数始终失败。

当尝试从attachResult 附加.msg 文件时,似乎附件没有失败,因为这是我们返回的结果:

但是,当我们使用以下函数检查附件是否失败时(使用 attachResult 对象上返回的 value 属性:

     public async didAttachFail(attachmentOutlookId: string): Promise<boolean> {
        const attachments = await new Promise(async results => {
            const mailboxItem = Office.context.mailbox.item;
            const options = { asyncContext: { currentItem: mailboxItem } };
            Office.context.mailbox.item.getAttachmentsAsync(
                options,
                (response: Office.AsyncResult<Office.AttachmentDetails[]>) => {
                    results(response);
                }
            );
        });
        // Atachments will have 0 size if they failed to download
        return (attachments as Office.AsyncResult<Office.AttachmentDetails[]>).value.some(
            x => x.id === attachmentOutlookId && x.size === 0
        );
    }

项目的大小似乎为 0 - 这反过来意味着它没有正确连接。从为addFileAttachmentAsync 指定的fileUrl 下载文件时(我已确认提供的 URL 有效),我可以清楚地看到该项目不是 0KB;

.msg 文件的附件方面我们做错了什么,或者有其他方法吗?概述的代码适用于各种其他内容类型,包括 Word 文档、图像、PowerPoint 和 Excel 文件。它仅对 Outlook 邮件/.msg 文件失败。

**编辑 1: 我在我的桌面上使用 Outlook 应用程序(版本 2005,内部版本 12827.20268),我的Windows version is 1909(内部版本 18363.900)。我还在 Outlook Online、Chrome(版本 83.0.4103.97)和 Microsoft Edge(版本 83.0.478.45)中对此进行了测试,结果相同。

**编辑 2:

  • 我可以手动添加这个 .msg 文件。
  • 此外,附加调试器时没有错误(这是有道理的,在查看使用 addFileAttachmentAsync 的输出时,附件的大小为 0)。
  • 所以最后一次调用是使用 Script Lab 测试所有内容(感谢您对此的提醒)并且;

这是我创建的脚本的 .yaml:https://gist.github.com/svbygoibear/9febca6eeaca5748d15995dd879cae64#file-add-attachments-outlook-outlook-yaml

现在我在这里制作了一大堆示例文档(一个图像、一个 .docx 和一个 .msg 文件)来测试addFileAttachmentAsync。所有文件(包括 .msg 文件)都正确附加,但如果您看到最后一种方法(即getAttachmentsAsync)的输出,您将看到 .msg 文件的大小为 0:

我们使用它来检查文件是否已正确附加 - 所以似乎问题出在getAttachmentsAsync。 .msg 文件是否会返回 0 大小?

【问题讨论】:

  • 您在哪个 Outlook 平台上遇到此问题?
  • 啊,让我在原始问题中添加所有版本号 - 但我在桌面上使用 Outlook 应用程序(版本 2005,内部版本 12827.20268),我的 Windows 版本是 1909(内部版本 18363.900)。我还在 Outlook Online、Chrome(版本 83.0.4103.97)和 Microsoft Edge(版本 83.0.478.45)中对此进行了测试,结果相同。
  • 我们无法重现此问题。您可以手动附加此文件吗?
  • 你能在 ScriptLab 中重现这个吗? Scriplab 是适用于 Outlook 的插件,可在商店中获得。从商店安装插件的说明可以在here 找到。在这个插件中,有一些示例 sn-ps,例如 "Manipulate attachments (Item Compose)" ,可用于尝试重现此问题。
  • 您也可以try attaching a debugger查看插件的任何问题。

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


【解决方案1】:

感谢您报告此问题。经过慎重考虑,我们的团队决定在短期内不修复这个问题。我们建议您投票或创建一个新的Uservoice 项目,这将使我们了解它的共性,并有助于我们确定优先级。如果我们最终解决了这个问题,我们将根据需要重新激活。

【讨论】:

    猜你喜欢
    • 2016-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多