首先,我要感谢所有回复我以制定解决方案的人。特别感谢@FreeAsInBeer 和 MrPiao。花了几天的时间后,我能够开发以下用于获取邮件标头的解决方案。我从代码中删除了所有不必要的业务逻辑,最后想出了以下代码。它可用于使用 JQuery 读取收件箱电子邮件的标题。
我正在外面发出 EWS 请求以获取标头。从它的回调方法中,我可以检索到预期的结果。之后,最好使用 jQuery.parseXML 来读取和操作响应(代码中不包含)
我希望这个解释会对你有所帮助。
var _mailbox;
var _ItemId1
(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();
_mailbox = Office.context.mailbox;
_ItemId1 = _mailbox.item.itemId;
});
};
})();
function getSelectedEmailHeaders() {
// Wrap an Exchange Web Services request in a SOAP envelope.
var var1 = '<?xml version="1.0" encoding="utf-8"?>';
var var2 = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
var var3 = ' <soap:Header>';
var var4 = ' <t:RequestServerVersion Version="Exchange2010" />';
var var5 = ' </soap:Header>';
var var6 = ' <soap:Body>';
var var7 = ' <m:GetItem>';
var var8 = ' <m:ItemShape>';
var var9 = ' <t:BaseShape>IdOnly</t:BaseShape>';
var var10 = ' <t:AdditionalProperties>';
var var11 = ' <t:FieldURI FieldURI="item:Subject" />';
var var12 = ' <t:FieldURI FieldURI="item:MimeContent" />';
var var13 = ' </t:AdditionalProperties>';
var var14 = ' </m:ItemShape>';
var var15 = ' <m:ItemIds>';
var var16 = ' <t:ItemId Id="' + _ItemId1 + '" />';
var var17 = ' </m:ItemIds>';
var var18 = ' </m:GetItem>';
var var19 = ' </soap:Body>';
var var20 = '</soap:Envelope>';
var envelopeForHeaders = var1 + var2 + var3 + var4 + var5 + var6 + var7 + var8 + var9 + var10 + var11 + var12 + var13 + var14 + var15 + var16 + var17 + var18 + var19 + var20;
//Calling EWS
_mailbox.makeEwsRequestAsync(envelopeForHeaders, callbackForHeaders);
}
//This Function called when the EWS request is complete.
function callbackForHeaders(asyncResult) {
//Write the content of the asyncResult on console
console.log(asyncResult);
}
谢谢你。贵霜兰迪玛