office365 - 使用 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:
- 我可以手动手动添加这个 .msg 文件。
- 此外,附加调试器时没有错误(这是有道理的,在查看 using 的输出时,附件的大小为 0
addFileAttachmentAsync
)。 - 所以最后一个电话是使用 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 大小?
解决方案
感谢您报告此问题。经过慎重考虑,我们的团队决定在短期内不修复这个问题。我们建议您投票或创建一个新的Uservoice项目,这将使我们了解它的共性,并有助于我们确定优先级。如果我们最终解决了这个问题,我们将根据需要重新激活。
推荐阅读
- python - 将来自多个站点的数据写入 JSON 文件 BeautifulSoup
- c# - Unity 中的 SQLite 数据库文件损坏
- javascript - 使用 AWS Lambda 自动创建静态站点客户端页面
- css - flexbox 对齐从中心偏移的项目,没有填充物
- c - realloc 将所有索引设置为相同的数据
- ios - 自动续订订阅错误的到期日期时间
- javascript - ShopPad的Infinite Options中是否有JavaScript的回调功能?
- php - 如何设置两个环境变量然后运行php-cgi?
- python - 从给定的字符可能性中列出所有可能的字符串
- jquery - 如何概括这些jquery函数?