【问题标题】:Office Outlook Add-in- Adding an attachment from a secure locationOffice Outlook 加载项 - 从安全位置添加附件
【发布时间】:2016-04-06 09:15:51
【问题描述】:

我正在添加一个“添加附件”命令作为 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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      猜你喜欢
      • 2019-03-22
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多