如何使用AJAX jquery
将附件从电子邮件保存到服务器文件夹我使用Node和Jquery开发Outlook Add-in。
'use strict';
(function () {
// The initialize function must be run each time a new page is loaded
Office.initialize = function (reason) {
$(document).ready(function () {
// After the DOM is loaded, app-specific code can run.
var sender_email = Office.context.mailbox.item.from.emailAddress; // Email Address
var sender_name = Office.context.mailbox.item.from.displayName; // Get Display Name
var subject = Office.context.mailbox.item.subject; // Get Subject
// Get Attachment from Outlooks Email.
var _Item = Office.context.mailbox.item;
if (_Item.attachments.length > 0) {
for (var i = 0 ; i < _Item.attachments.length ; i++) {
var _att = _Item.attachments[i];
console.log(i + ". Name: ");
console.log(_att.name);
console.log(" ID: " + _att.id);
console.log(" contentType: " + _att.contentType);
console.log(" size: " + _att.size);
console.log(" attachmentType: " + _att.attachmentType);
console.log(" isInline: " + _att.isInline);
}
}
// Do something with outputString
// I need Outlook Email Attachment upload attachment on Specific server using Ajax Jquery
var url = 'URL';
$.ajax({
url: url,
type: "POST",
data: {'attachment': attachment},
dataType: "JSON",
success: function (response) {
if (response.success == 1) {
console.log("Upload");
} else {
console.log("Error in Uploading attachment");
}
}
});
}
}
}
控制台日志:
Name: Blank PDF Document.pdf
ID: AQMkADAwATM3ZmYAZS0wZTI1LTdlZQAxLTAwAi0wMAoARgAAA/y1A2YhzU1Bk05UvY0yWPQHAMN19wxC7xpPgbGB+hr4/lcAAAIBDAAAAMN19wxC7xpPgbGB+hr4/lcAAAADoVHPAAAAARIAEAC1Pk4zZiVsSKgpipMFf0rW
contentType: application/pdf
size: 4785
attachmentType: file
isInline: false
答案 0 :(得分:0)
附件对象本身没有附件内容。它只包含附件中的元数据。您可以使用为附件指定的ID并进行REST查询以获取附件的内容并将其下载到您的服务器。
您可以在此处参考文档:https://docs.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item