Office Outlook 加载项 - 从安全位置添加附件
Office Outlook Add-in- Adding an attachment from a secure location
我正在添加 "Add attachment" 命令作为 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
如果您尝试将用户 PC 上的本地文件附加到电子邮件中,那么很遗憾,您不能这样做,因为这当然是 JavaScript。 Outlook 插件 API 中的附件方法只能处理基于 Web 的文件。您需要一个 Web 表单或其他机制来将文件上传到您的 Web 服务到一个可访问的 URI 位置,然后您可以使用 addFileAttachmentAsync 方法指向该位置。 ASP.NET Web API 将是实现您的 Web 服务的一种替代方法。
在 addFileAttachmentAsync
中,attachmentURI
参数被发送到服务器(在 OWA 的情况下)或 Outlook 应用程序(桌面 Outlook)。然后,服务器或 Outlook 开始下载文件,并将其附加到电子邮件中。如果 OWA/Outlook 无法到达您提供的 URI,则它将不起作用。
我正在添加 "Add attachment" 命令作为 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
如果您尝试将用户 PC 上的本地文件附加到电子邮件中,那么很遗憾,您不能这样做,因为这当然是 JavaScript。 Outlook 插件 API 中的附件方法只能处理基于 Web 的文件。您需要一个 Web 表单或其他机制来将文件上传到您的 Web 服务到一个可访问的 URI 位置,然后您可以使用 addFileAttachmentAsync 方法指向该位置。 ASP.NET Web API 将是实现您的 Web 服务的一种替代方法。
在 addFileAttachmentAsync
中,attachmentURI
参数被发送到服务器(在 OWA 的情况下)或 Outlook 应用程序(桌面 Outlook)。然后,服务器或 Outlook 开始下载文件,并将其附加到电子邮件中。如果 OWA/Outlook 无法到达您提供的 URI,则它将不起作用。