• Sign in
 
  •  
  • MSDN Blogs
  • Microsoft Blog Images
  • More ...

  • Blog Home
  • About
  • Email Blog Author
  • Share this
  • RSS for posts
  • Atom
  • RSS for comments
  • CDO (24)
  • Code Snippet (43)
  • Custom Providers (17)
  • Debugging (7)
  • DevMsgTeam (300)
  • Documentation (108)
  • DST (8)
  • EWS (7)
  • Exchange (108)
  • Gotchas (97)
  • Hotfix (28)
  • MAPI (239)
  • MAPI Download (53)
  • MFCMAPI (101)
  • MSDN (59)
  • Non Dev (11)
  • OOM (17)
  • Outlook (171)
  • Outlook 2007 Auxiliary Reference (45)
  • Outlook Integration API (12)
  • Protocol Docs (20)
  • PST/OST (23)
  • Referrals (8)
  • Vista (12)
  • WrapPST (18)
Links:
  • Download MFCMAPI
  • MFCMAPI on Facebook
  • Troubleshooting Outlook Crashes
  • Office Update Center
  • Developer Messaging Team Blog
This site is provided "AS IS" with no warranties, and confers no rights. Use of included code samples are subject to the terms specified in the Terms of Use.
Archives
  • May 2013 (2)
  • April 2013 (1)
  • March 2013 (2)
  • February 2013 (2)
  • January 2013 (2)
  • December 2012 (4)
  • November 2012 (2)
  • October 2012 (2)
  • September 2012 (1)
  • August 2012 (3)
  • June 2012 (2)
  • May 2012 (1)
  • April 2012 (3)
  • March 2012 (3)
  • February 2012 (3)
  • January 2012 (1)
  • December 2011 (3)
  • November 2011 (1)
  • October 2011 (3)
  • September 2011 (1)
  • August 2011 (1)
  • July 2011 (4)
  • June 2011 (3)
  • May 2011 (3)
  • April 2011 (3)
  • March 2011 (5)
  • February 2011 (1)
  • January 2011 (2)
  • December 2010 (1)
  • November 2010 (4)
  • October 2010 (1)
  • September 2010 (3)
  • August 2010 (5)
  • July 2010 (3)
  • June 2010 (3)
  • May 2010 (1)
  • April 2010 (3)
  • March 2010 (3)
  • February 2010 (3)
  • January 2010 (2)
  • December 2009 (3)
  • November 2009 (5)
  • October 2009 (4)
  • September 2009 (5)
  • August 2009 (5)
  • July 2009 (11)
  • June 2009 (6)
  • May 2009 (5)
  • April 2009 (3)
  • March 2009 (18)
  • February 2009 (10)
  • January 2009 (3)
  • December 2008 (2)
  • November 2008 (2)
  • October 2008 (5)
  • September 2008 (4)
  • August 2008 (10)
  • July 2008 (6)
  • June 2008 (8)
  • May 2008 (2)
  • April 2008 (4)
  • March 2008 (2)
  • February 2008 (2)
  • January 2008 (5)
  • December 2007 (3)
  • November 2007 (2)
  • October 2007 (3)
  • September 2007 (1)
  • August 2007 (4)
  • July 2007 (5)
  • June 2007 (3)
  • May 2007 (4)
  • April 2007 (1)
  • March 2007 (6)
  • February 2007 (3)
  • January 2007 (2)
  • December 2006 (4)
  • November 2006 (3)
  • October 2006 (1)
  • August 2006 (1)
  • June 2006 (5)
  • May 2006 (5)
  • December 2005 (1)
  • November 2005 (4)
  • October 2005 (2)
  • September 2005 (1)
  • April 2005 (3)
  • December 2004 (2)
  • September 2004 (2)
  • August 2004 (3)
  • July 2004 (3)

Exchange Web Services and Internet Message Headers

MSDN Blogs > SGriffin's MAPI Internals > Exchange Web Services and Internet Message Headers

Exchange Web Services and Internet Message Headers

Stephen Griffin - MSFT
9 Feb 2007 1:18 PM
  • Comments 12

We had a customer asking how to use the InternetMessageHeaders property in EWS. They found that if they asked for the prop, they only got the names of the headers, but not the values. This is one of those areas (like attachments) where EWS is only going to fetch the minimal amount of data, avoiding potentially expensive operations until you explicitly ask for them. In this case, once you have the names of the headers, you can make another call back to fetch their values. Of course, if you already knew the name of a header you wanted, then you could skip the middle step and ask for it directly.

I've updated my earlier sample to illustrate the technique.

using System;
using EWS;
using System.Net;

namespace GetProps
{
  class Program
  {
    static void Main(string[] args)
    {
      ExchangeServiceBinding exchangeServer = new ExchangeServiceBinding();
      ICredentials creds = new NetworkCredential("SomeUser", "SomePassword", "SomeDomain");

      exchangeServer.Credentials = creds;
      exchangeServer.Url = @"http://MyServer/EWS/Exchange.asmx";

      DistinguishedFolderIdType[] folderIDArray = new DistinguishedFolderIdType[1];
      folderIDArray[0] = new DistinguishedFolderIdType();
      folderIDArray[0].Id = DistinguishedFolderIdNameType.inbox;

      PathToUnindexedFieldType ptuftDisplayName = new PathToUnindexedFieldType();
      ptuftDisplayName.FieldURI = UnindexedFieldURIType.folderDisplayName;

      PathToExtendedFieldType pteftComment = new PathToExtendedFieldType();
      pteftComment.PropertyTag = "0x3004"; // PR_COMMENT
      pteftComment.PropertyType = MapiPropertyTypeType.String;

      GetFolderType myfoldertype = new GetFolderType();
      myfoldertype.FolderIds = folderIDArray;
      myfoldertype.FolderShape = new FolderResponseShapeType();
      myfoldertype.FolderShape.BaseShape = DefaultShapeNamesType.IdOnly;
      myfoldertype.FolderShape.AdditionalProperties = new BasePathToElementType[2];
      myfoldertype.FolderShape.AdditionalProperties[0] = ptuftDisplayName;
      myfoldertype.FolderShape.AdditionalProperties[1] = pteftComment;

      Console.WriteLine("Getting inbox");
      GetFolderResponseType myFolder = exchangeServer.GetFolder(myfoldertype);

      FolderInfoResponseMessageType firmtInbox = 
      (FolderInfoResponseMessageType) myFolder.ResponseMessages.Items[0];

      Console.WriteLine("got folder: {0}",firmtInbox.Folders[0].DisplayName);

      if (null != firmtInbox.Folders[0].ExtendedProperty)
      {
        Console.WriteLine("Comment: {0}",firmtInbox.Folders[0].ExtendedProperty[0].Item.ToString());
      }
      else
      {
        Console.WriteLine("Comment: not found");
      }

      PathToUnindexedFieldType ptuftSubject = new PathToUnindexedFieldType();
      ptuftSubject.FieldURI = UnindexedFieldURIType.itemSubject;

      PathToExtendedFieldType pteftFlagStatus = new PathToExtendedFieldType();
      pteftFlagStatus.PropertyTag = "0x1090"; // PR_FLAG_STATUS
      pteftFlagStatus.PropertyType = MapiPropertyTypeType.Integer;

      FindItemType findItemRequest = new FindItemType();
      findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
      findItemRequest.ItemShape = new ItemResponseShapeType();
      findItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
      findItemRequest.ItemShape.AdditionalProperties = new BasePathToElementType[2];
      findItemRequest.ItemShape.AdditionalProperties[0] = ptuftSubject;
      findItemRequest.ItemShape.AdditionalProperties[1] = pteftFlagStatus;
      findItemRequest.ParentFolderIds = new FolderIdType[] { firmtInbox.Folders[0].FolderId };

      FindItemResponseType firt = exchangeServer.FindItem(findItemRequest);

      foreach (FindItemResponseMessageType firmtMessage in firt.ResponseMessages.Items)
      {
        if (null != firmtMessage.RootFolder && firmtMessage.RootFolder.TotalItemsInView > 0)
        {
          foreach (ItemType it in ((ArrayOfRealItemsType)firmtMessage.RootFolder.Item).Items)
          {
            Console.WriteLine("got item: {0}",it.Subject);
            if (null != it.ExtendedProperty)
            {
              Console.WriteLine("Prop PR_FLAG_STATUS: {0}",it.ExtendedProperty[0].Item.ToString());
            }
            else
            {
              Console.WriteLine("Prop PR_FLAG_STATUS: not found");
            }

            PathToUnindexedFieldType ptuftHeaders = new PathToUnindexedFieldType();
            ptuftHeaders.FieldURI = UnindexedFieldURIType.itemInternetMessageHeaders;

            PathToExtendedFieldType ptuftHeadersProp = new PathToExtendedFieldType();
            ptuftHeadersProp.PropertyTag = "0x007D"; // PR_TRANSPORT_MESSAGE_HEADERS
            ptuftHeadersProp.PropertyType = MapiPropertyTypeType.String;

            GetItemType getItemRequest = new GetItemType();
            getItemRequest.ItemIds = new ItemIdType[] { it.ItemId };
            getItemRequest.ItemShape = new ItemResponseShapeType();
            getItemRequest.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
            getItemRequest.ItemShape.AdditionalProperties = new BasePathToElementType[2];
            getItemRequest.ItemShape.AdditionalProperties[0] = ptuftHeaders;
            getItemRequest.ItemShape.AdditionalProperties[1] = ptuftHeadersProp;

            GetItemResponseType girt = exchangeServer.GetItem(getItemRequest);
            foreach (ItemInfoResponseMessageType grmtMessage in girt.ResponseMessages.Items)
            {
              ItemType item = grmtMessage.Items.Items[0];
              if (null != item.ExtendedProperty)
              {
                Console.WriteLine("Prop PR_TRANSPORT_MESSAGE_HEADERS:\n {0}", item.ExtendedProperty[0].Item.ToString());
              }
              else
              {
                Console.WriteLine("Prop PR_TRANSPORT_MESSAGE_HEADERS: not found");
              }
              Console.WriteLine();

              if (null != item.InternetMessageHeaders)
              {
                PathToIndexedFieldType[] headerProps = new PathToIndexedFieldType[item.InternetMessageHeaders.Length];
                int index = 0;
                foreach (InternetHeaderType iht in item.InternetMessageHeaders)
                {
                  PathToIndexedFieldType headerProp = new PathToIndexedFieldType();
                  headerProp.FieldURI = DictionaryURIType.itemInternetMessageHeader;
                  headerProp.FieldIndex = iht.HeaderName;
                  headerProps[index++] = headerProp;
                }

                GetItemType getItemRequest2 = new GetItemType();
                getItemRequest2.ItemIds = new ItemIdType[] { it.ItemId };
                getItemRequest2.ItemShape = new ItemResponseShapeType();
                getItemRequest2.ItemShape.BaseShape = DefaultShapeNamesType.IdOnly;
                getItemRequest2.ItemShape.AdditionalProperties = headerProps;

                GetItemResponseType girt2 = exchangeServer.GetItem(getItemRequest2);
                foreach (ItemInfoResponseMessageType grmtMessage2 in girt2.ResponseMessages.Items)
                {
                  ItemType item2 = grmtMessage2.Items.Items[0];
                  if (null != item2.InternetMessageHeaders)
                  {
                    Console.Write("Parsing internet headers");
                    foreach (InternetHeaderType iht2 in item2.InternetMessageHeaders)
                    {
                      if (null != iht2.HeaderName)
                      {
                        Console.Write("Header {0}", iht2.HeaderName.ToString());
                        if (null != iht2.Value)
                        {
                          Console.WriteLine(" = {0}", iht2.Value.ToString());
                        }
                        else Console.WriteLine(" is null");
                      }
                    }
                  }
                }
              }
            }
            Console.WriteLine();
          }
        }
      }

      Console.WriteLine("\nHit any key to continue");
      Console.ReadKey(true);
    }
  }
}
  • 12 Comments
Exchange, Code Snippet, EWS, DevMsgTeam
Comments
  • anoop
    24 Mar 2007 3:26 AM

    an article for Pull Subscriptions using Exchange 2007 web service

  • anoop
    24 Mar 2007 3:27 AM

    I would love to have an active bloggin for exchange 2007 stufss since no where in internet is having enough articles

  • Daniel
    25 Apr 2007 1:47 AM

    Dear, would it be possible to add a meeting to MS Exchange through the new Web services or throught ADSI or anyway you think it can happen. Thanks.

  • Rajiv
    2 May 2007 7:47 PM

    I want to create an item to be sent on desired future date. How and where in EWS I can do that. Do you have any snippet code which does this?

  • Nayan's [MSFT] Blog
    29 Jun 2007 5:02 PM

    Futher to SGriffin's Weblog as below: http://blogs.msdn.com/stephen_griffin/archive/2007/02/09/exchange-web-services-and-internet-message-headers.aspx

  • Bob
    18 Nov 2007 3:32 AM

    Hi SGriffin:

    I want to know how to add custom Internet Message Header in Messages , and then I can get it by your program up...

    Can you give me some tips?

    thank you very much!!

  • Stephen Griffin - MSFT
    18 Nov 2007 11:53 AM

    Internet message headers are there on a message that came in from the internet. So the answer would depend greatly on how you plan on creating and sending your messages.

  • Aaron
    3 Dec 2007 6:44 PM

    Hi SGriffin

    I was looking at your previous reply and the sample. So, if I want to duplicate a message after I delete the original from Exchange, would I be able to do so using EWS or any means of Exchange 2007 SDK, keeping the same MAPI properties and Internet Headers?

    Thanks so much,

    Aaron

  • Neil
    10 Apr 2008 8:57 AM

    Hi Grifin,

    My question is also similar to bob...

    how can we add custom Internet Message Header in a Mail Message created using createItem request in EWS.

    suppose i want to add a header like

    msg-originator=abc.def.com

    Please give me some inputs..

    TIA

    ~Neil

  • Tomas
    9 Jun 2008 9:02 AM

    HI Grifin,

    How can I specify which X-Header to get back from the response ? I already know the message header I'm interested in ? Is it possible to specify it via GetItem request ?

    thx

    Thomas

  • Dan's WebDAV 101
    2 Oct 2008 5:02 PM

    I've put together a list of articles which cover common questions on Exchange Web Services (EWS). These

  • Dan's WebDAV 101
    2 Oct 2008 7:55 PM

    I've put together a list of articles which cover common questions on Exchange Web Services (EWS). These

Page 1 of 1 (12 items)
Leave a Comment
  • Please add 8 and 2 and type the answer here:
  • Post
  • © 2013 Microsoft Corporation.
  • Terms of Use
  • Trademarks
  • Privacy & Cookies
  • Report Abuse
  • 5.6.426.415