Exchange Web Services and MAPI Props

Merry Christmas! With Exchange 12 (whoops! Exchange 2007) just around the corner, we’re starting to get questions about Exchange Web Services. I just helped a customer with a sample illustrating the use of AdditionalProperties to fetch arbitrary MAPI properties from folders and messages. I figured I should clean up the sample and share it with the world.

Comment #1: It wasn’t clear to me how to generate the web service proxy in Visual Studio. I don’t do development directly on my Exchange server, so it wasn’t as easy as doing “Add Web Reference” and picking “Web Services on the local machine”. I finally found a reference indicating you can use either of these:


Incidently, neither of these URLs is documented in the Exchange 2007 SDK. Maybe someone more familiar with web services would have found it obvious, but I certainly didn’t. The SDK folks are working to correct this oversight.

Comment #2: The object ExchangeServiceBinding isn’t documented in the SDK either. I had to borrow snippets from other samples to figure out how to use it. The SDK folks are working on that too.

Comment #3: The usual caveats for samples apply here – use at your own risk. Error handling is minimal, so if it crashes – it’s not my fault. Enjoy!

using System;
using System.Net;
using EWS; //this is the web reference

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());
                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[1];
            findItemRequest.ParentFolderIds[0] = firmtInbox.Folders[0].FolderId;

            FindItemResponseType firt = exchangeServer.FindItem(findItemRequest);

            foreach (FindItemResponseMessageType firmtMessage in firt.ResponseMessages.Items)
                if (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 0x1090: {0}",it.ExtendedProperty[0].Item.ToString());
                            Console.WriteLine("Prop 0x1090: not found");

            Console.WriteLine("\nHit any key to continue");
Comments (12)

  1. Here are some Exchange 2007 Web Services resources from around the web… Microsoft Resources VIDEO:

  2. Question How do I access my Outlook contacts from my web application? Short Answer You don’t, well at

  3. Wes' Blog says:

    Question How do I access my Outlook contacts from my web application? Short Answer You don’t, well at

  4. Mani says:

    Can you post the services.wsdl online? I would like to see it without installing exchange 2007…

  5. Mudit says:

    HOw to do this a mobile not using Outlook(hence no POOM)?

  6. Stephen Griffin says:

    If it’s possible to issue HTTP requests from your mobile, then you should be able to use a web service. So – however you would use a web service from there, you can adapt that to use EWS.

  7. Shilpa Bhasin says:

    I am working on a problem where I want to decode a TNEF encoded MIME message. I am using the class Base64Decode in namespace and I am also able to decode the message if it doesn’t contain an attachment . But , for a TNEF encoded message without attachment , the conversion fails. Do you have any suggestions ? Please help .

    In addition to that , could you provide me some sample code to parse a MIME message using MimeDocument,MimeReader and Tnef Reader classes?

    Thanks in advance

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

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

  10. Renata says:

    I have a big problem. I have a VB application that gets users from Exchange server, and gets their calendars using MAPI.

    Now I’m porting that application to .NET and I’m using Exchange Web Service API. The problem is that I can’t take the PR_STORE_ENTRYID Property of the contact. Within the old code, I took it by AddressEntry.ID and I store that in database, and now I should take that StoreID with EWS API, but I don’t know how. I know that I should use ExtendedProperties, and PropertyID = "Ox0FFB", but have no idea in which way :(

    Please, I appreciate if you can help me.


  11. Sven Hornberg says:

    I’m currently trying to include exchange webservices 2007 functionality in a custom web application which is running on a Windows 2008 Server (IIS 7, Exchange Server 2007).

    How do I access exchange 2007 webservices from my web application ? I currently use the defaultcredentials and receive an error, saying I don’t have the required authorization (error 401).

    Stating the credentials explicitly in the code works perfectly fine when trying to execute the code remotely, whether including the domain or not.

    When executing the code locally on either the web server or my client computer, no problems occur. The web application I intend to write is supposed to run on the server and be accessed from any computer via my company’s intranet.

    The code looks something like this..

    ExchangeServiceBinding binding = new ExchangeServiceBinding();

    binding.Url = @"https://server/ews/exchange.asmx";

    binding.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

    CreateItemType createItemType = new CreateItemType();

    .. (creating item and setting it’s properties)



     CreateItemResponseType createItemResponse = binding.CreateItem(createItemType); <- the error seems to occur here  }  catch (Exception ex)  {

     Response.Write(ex.ToString()); <- results in error "unauthorized"


    The authentication settings in IIS 7 are as follows:

    anonymous authentication: deactivated

    ASP.NET multiple identities: activated

    digest authentication: deactivated

    forms authentication: deactivated

    standard authentication: deactivated

    windows authentication: deactivated

    User permissions set:

    SYSTEM: full access rights

    (windows user): full access rights

    IUSR: full access

  12. ExchangeWebServices Namespace says:

    I'm trying to use classes and methods documented in the Namespace ExchangeWebServices but when I add the Web reference can not get all methods and classes that allow me to do Bulk Transfer Operations  with ExportItems Operation and Operation UploadItems as shown in the documentation: .com/en-us/library/bb409286.aspx.