1

我正在添加一个“添加附件”命令作为 Office Outlook 加载项的一部分。

我想找到一种从具有授权的 URL 添加文件的方法。

我想用 ajax 下载它,然后从 blob 中保存它,但看起来该命令不支持它。我的代码测试它失败了:

const text = 'attachment content';
const blob = new Blob([text], {type: 'text/plain'});
const attachmentURI = window.URL.createObjectURL(blob);

Office.context.mailbox.item.addFileAttachmentAsync(
  attachmentURI,
  'file.txt',
  { asyncContext: null },
  function (asyncResult) {
    if(asyncResult.status == Office.AsyncResultStatus.Failed){
       console.log('error adding attachment: ' + asyncResult.error.message);
    }
    else {
      const attachmentID = asyncResult.value;
      console.log('added attachment: ' + attachmentID);
    }
  }
);

有关从具有权限的 URL 保存附件的任何建议?

功能文档: https ://dev.office.com/docs/add-ins/outlook/add-and-remove-attachments-to-an-item-in-a-compose-form

4

2 回答 2

2

如果您尝试将本地文件从用户的 PC 附加到电子邮件,那么很遗憾您不能这样做,因为这当然是 JavaScript。Outlook Add-in API 中的附件方法只能处理基于 Web 的文件。您需要一个 Web 表单或其他机制将文件上传到您的 Web 服务到可访问的 URI 位置,然后您可以使用 addFileAttachmentAsync 方法指向该位置。ASP.NET Web API 将是实现 Web 服务的一种替代方法。

于 2016-04-07T03:32:50.390 回答
1

在参数被发送addFileAttachmentAsyncattachmentURI服务器(在 OWA 的情况下),或到 Outlook 应用程序(桌面 Outlook)。然后,服务器或 Outlook 下载文件,并将其附加到电子邮件中。如果 OWA/Outlook 无法访问您提供的 URI,那么它将无法工作。

于 2016-05-02T19:57:43.560 回答