如何使用 AJAX jquery 将 Outlook 电子邮件项目中的附件保存到服务器文件夹中

How to save attachments from Outlook Email Items into the server folder using AJAX jquery

如何使用 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

附件对象本身没有附件内容。它只包含有关附件的元数据。您可以使用为附件提供的 ID 并进行 REST 查询以获取附件的内容并将其下载到您的服务器。

您可以在此处参考文档:https://docs.microsoft.com/en-us/outlook/add-ins/get-attachments-of-an-outlook-item