Read email headers in Outlook Web Access (OWA)

只谈情不闲聊 提交于 2019-11-30 16:20:15

First of all, I would like to thank all the persons who responded me to develop a solution for the this. Special thanks should goes to @FreeAsInBeer and MrPiao. After spending several days I was lucky to develop a perfect solution for getting mail headers (My Tech-lead helped me a lot in this). This works fine. I got some time and removed all the unnecessary business logic from the code and finally come up with the following code. I think now any one can use it for reading the headers of inbox emails using J Query.

I am making an EWS request outside to get the headers. From it callback method I can retrieve the expected result. Afterwards, it is better to use jQuery.parseXML to read and manipulate the response (which is not included in the code)

I hope this explanation will help you.

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);
}

Thank You. Kushan Randima

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!