首页 > 解决方案 > 使用 addFileAttachmentAsync 附加 .msg 文件失败

问题描述

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

     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

当试图附加一个.msg文件时,attachResult似乎附件没有失败,因为这是我们得到的结果: 附加结果对象

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

     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 - 这反过来意味着它没有正确连接。从fileUrl指定的文件下载文件时addFileAttachmentAsync(我已经确认提供的 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:

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

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

在此处输入图像描述

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

标签: office365office-jsoffice-addinsoutlook-web-addins

解决方案


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


推荐阅读