如何使用outlook Js加载项在我的云服务器上上载outlook电子邮件附件
我正在使用vs2017开发outlook javascript加载项。我创建了一个示例应用程序,用于从outlook邮件项目中查找附件。在这里,当从Exchange Server获取附件时,它返回200 OK 我有自己的云应用程序,看起来像谷歌硬盘。我想使用POST API调用在云服务器上上载outlook邮件附件。API调用已成功运行。但我无法从exchange服务器获取文件内容 我在这里添加了一些示例代码如何使用outlook Js加载项在我的云服务器上上载outlook电子邮件附件,outlook,office-js,outlook-web-addins,javascript-api-for-office,Outlook,Office Js,Outlook Web Addins,Javascript Api For Office,我正在使用vs2017开发outlook javascript加载项。我创建了一个示例应用程序,用于从outlook邮件项目中查找附件。在这里,当从Exchange Server获取附件时,它返回200 OK 我有自己的云应用程序,看起来像谷歌硬盘。我想使用POST API调用在云服务器上上载outlook邮件附件。API调用已成功运行。但我无法从exchange服务器获取文件内容 我在这里添加了一些示例代码 创建服务请求 /// <reference path="../
- 创建服务请求
/// <reference path="../App.js" /> var xhr; var serviceRequest; (function () { "use strict"; // The Office initialize function must be run each time a new page is loaded Office.initialize = function (reason) { $(document).ready(function () { app.initialize(); initApp(); }); }; function initApp() { $("#footer").hide(); if (Office.context.mailbox.item.attachments == undefined) { var testButton = document.getElementById("testButton"); testButton.onclick = ""; showToast("Not supported", "Attachments are not supported by your Exchange server."); } else if (Office.context.mailbox.item.attachments.length == 0) { var testButton = document.getElementById("testButton"); testButton.onclick = ""; showToast("No attachments", "There are no attachments on this item."); } else { // Initalize a context object for the app. // Set the fields that are used on the request // object to default values. serviceRequest = new Object(); serviceRequest.attachmentToken = ""; serviceRequest.ewsUrl = Office.context.mailbox.ewsUrl; serviceRequest.attachments = new Array(); } }; })(); function testAttachments() { Office.context.mailbox.getCallbackTokenAsync(attachmentTokenCallback); }; function attachmentTokenCallback(asyncResult, userContext) { if (asyncResult.status == "succeeded") { serviceRequest.attachmentToken = asyncResult.value; makeServiceRequest(); } else { showToast("Error", "Could not get callback token: " + asyncResult.error.message); } } function makeServiceRequest() { var attachment; xhr = new XMLHttpRequest(); // Update the URL to point to your service location. xhr.open("POST", "https://localhost:8080/GetOutlookAttachments/AttachmentExampleService/api/AttachmentService", true); xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8"); xhr.onreadystatechange = requestReadyStateChange; // Translate the attachment details into a form easily understood by WCF. for (i = 0; i < Office.context.mailbox.item.attachments.length; i++) { attachment = Office.context.mailbox.item.attachments[i]; attachment = attachment._data$p$0 || attachment.$0_0; if (attachment !== undefined) { serviceRequest.attachments[i] = JSON.parse(JSON.stringify(attachment)); } } // Send the request. The response is handled in the // requestReadyStateChange function. xhr.send(JSON.stringify(serviceRequest)); }; // Handles the response from the JSON web service. function requestReadyStateChange() { if (xhr.readyState == 4) { if (xhr.status == 200) { var response = JSON.parse(xhr.responseText); if (!response.isError) { // The response indicates that the server recognized // the client identity and processed the request. // Show the response. var names = "<h2>Attachments processed: " + response.attachmentsProcessed + "</h2>"; document.getElementById("names").innerHTML = names; } else { showToast("Runtime error", response.message); } } else { if (xhr.status == 404) { showToast("Service not found", "The app server could not be found."); } else { showToast("Unknown error", "There was an unexpected error: " + xhr.status + " -- " + xhr.statusText); } } } }; // Shows the service response. function showResponse(response) { showToast("Service Response", "Attachments processed: " + response.attachmentsProcessed); } // Displays a message for 10 seconds. function showToast(title, message) { var notice = document.getElementById("notice"); var output = document.getElementById('output'); notice.innerHTML = title; output.innerHTML = message; $("#footer").show("slow"); window.setTimeout(function () { $("#footer").hide("slow") }, 10000); };
// var-xhr; var服务请求; (功能(){ “严格使用”; //每次加载新页面时,必须运行Office初始化功能 Office.initialize=函数(原因){ $(文档).ready(函数(){ app.initialize(); initApp(); }); }; 函数initApp(){ $(“#页脚”).hide(); if(Office.context.mailbox.item.attachments==未定义){ var testButton=document.getElementById(“testButton”); testButton.onclick=“”; showToast(“不支持”,“Exchange服务器不支持附件”); }else if(Office.context.mailbox.item.attachments.length==0){ var testButton=document.getElementById(“testButton”); testButton.onclick=“”; showToast(“无附件”,“此项目上没有附件”); }否则{ //初始化应用程序的上下文对象。 //设置请求中使用的字段 //对象设置为默认值。 serviceRequest=新对象(); serviceRequest.attachmentToken=“”; serviceRequest.ewsUrl=Office.context.mailbox.ewsUrl; serviceRequest.attachments=新数组(); } }; })(); 函数testAttachments(){ Office.context.mailbox.getCallbackTokenAsync(attachmentTokenCallback); }; 函数attachmentTokenCallback(asyncResult,userContext){ 如果(asyncResult.status==“成功”){ serviceRequest.attachmentToken=asyncResult.value; makeServiceRequest(); } 否则{ showToast(“错误”,“无法获取回调令牌:”+asyncResult.Error.message); } } 函数makeServiceRequest(){ var附件; xhr=newXMLHttpRequest(); //更新URL以指向您的服务位置。 xhr.open(“POST”https://localhost:8080/GetOutlookAttachments/AttachmentExampleService/api/AttachmentService“,对); setRequestHeader(“内容类型”,“应用程序/json;字符集=utf-8”); xhr.onreadystatechange=requestReadyStateChange; //将附件详细信息转换为WCF易于理解的格式。 对于(i=0;i
请帮助我从outlook mail获取附件并上载到我的云服务器。附件。\数据$p$0提供给附件元数据。从那里获取id并使用getAttachmentContentAsync API获取附件内容。\数据$p$0提供给附件元数据。从那里获取id,并使用getAttachmentContentAsync API获取附件内容