4

I am developing a outlook Web App (Office 365 Developer). Regarding that, is there a way to read the headers of the selected mail which lays on inbox?. I am using Exchange server 2013. I would like to use Jquery or Javascript for write the code.

I tried to add "Message Header Analyzer" from Microsoft ( link:- 'https://store.office.com/message-header-analyzer-WA104005406.aspx?assetid=WA104005406'). Now it is working properly and it can read headers. But I need to implement the same functionality using my own codes.

If anyone can provide a good reference as a start, I would greatly appreciated that. (because, I got a great effort in searching google. But.. still no luck)

thanks in advance.

Kushan Randima
  • 2,174
  • 5
  • 31
  • 58
  • 1
    @user1800337 Why don't you post what you've tried so far. We're not here to do your job for you. – FreeAsInBeer Sep 29 '14 at 18:14
  • 1
    For what version of Exchange ? if its 2013\Office365 then look at the following MailApp https://store.office.com/message-header-analyzer-WA104005406.aspx?assetid=WA104005406 – Glen Scales Sep 30 '14 at 04:36
  • 1
    If you're not on 2013/Office 365 then you cannot extend OWA to show email headers. Of course, you should be able to make an EWS request outside to get the headers though... – MrPiao Oct 01 '14 at 00:57
  • @ Glen Scales, Thanks a lot for providing this link. I think it may be the solution for getting this done. But unfortunately, it directs me to 404 when I press "ADD" button there. – Kushan Randima Oct 06 '14 at 06:35
  • @FreeAsInBeer, I am sorry. I was not able to develop any considerable solution so far. This is a kind of research for me. Thank you – Kushan Randima Oct 29 '14 at 08:42
  • @MrPiao, Thanks for the idea. I think that I will stick on your suggestion as the last plan. I am trying to this by my app itself. – Kushan Randima Oct 29 '14 at 08:44
  • @FreeAsInBeer, Do you see any mistakes/areas to be improved in my question? (Because it is still down-voted). If there any, please be kind enough to show me the mistake(s) that I have done. Then I can correct/improve my self. Thank you so much. – Kushan Randima Oct 29 '14 at 09:30
  • @KushanRandima Your question looks a little better now that you've edited it. Regarding your question, I don't see any way to grab the message headers from a message. Why are you needing them? – FreeAsInBeer Oct 29 '14 at 12:58
  • @FreeAsInBeer, Thanks for your concern, I will explain the business logic. I develop this app for a company who try to "Fight Back Against Phishing". They need users to report the suspected mails. The company also sending spams to users as 'training mails'. In such occations, if user is smart enough for report the training mail as a spam, App would congrats user. The company sends some hidden information withing training mail headers to identify it as a training mail. That's why I want to read mail headers after user clicks report button. Thanks again. – Kushan Randima Oct 30 '14 at 05:03
  • @KushanRandima What's wrong with using the library you linked? Why must you read the headers yourself? – FreeAsInBeer Oct 30 '14 at 12:39
  • @FreeAsInBeer, I'm sorry. It is not a library. It is just a Outlook web as mine. Which can run as a user. I did not see any workaround to retrieving data from that App using my code. Can you still see any mistakes in my question? If so, please let me know (If I'm not bothering you). Because I am a beginner and I like to improve my self in asking questions. Thank You – Kushan Randima Oct 31 '14 at 04:09
  • @FreeAsInBeer, Correction :- It is just a Outlook web App as mine. – Kushan Randima Oct 31 '14 at 08:57

1 Answers1

2

First of all, I would like to thank all the persons who responded to me to develop a solution to this. Special thanks should go to @FreeAsInBeer and MrPiao. After spending several days I was able to develop the following solution for getting mail headers. I removed all the unnecessary business logic from the code and finally came up with the following code. It can be used for reading the headers of inbox emails using JQuery.

I am making an EWS request outside to get the headers. From its 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

Kushan Randima
  • 2,174
  • 5
  • 31
  • 58