Access Mail Box using EWS RRS feed

  • Question

  • Hi,

    I'm trying to use Exchange Web Services to access mailbox content.The Exchange Web Service URL is accessing the URL from my code throws 401:Unauthorized Access Error.

    Code Snippet:

    ExchangeServiceBinding binding = new ExchangeServiceBinding();
                binding.Credentials = new NetworkCredential(windowsliveid, password);
                binding.Url = "";
                FindItemType request = new FindItemType();
                request.ItemShape = new ItemResponseShapeType();
                request.ItemShape.BaseShape = DefaultShapeNamesType.AllProperties;
                DistinguishedFolderIdType folder = new DistinguishedFolderIdType();
                folder.Id = DistinguishedFolderIdNameType.inbox;
                folder.Mailbox = new EmailAddressType();
                folder.Mailbox.EmailAddress = windowsLiveUserId;
                request.ParentFolderIds = new BaseFolderIdType[] { folder };
                request.Traversal = ItemQueryTraversalType.Shallow;
                ItemType[] messages = null;
                    FindItemResponseType response = binding.FindItem(request);
                    FindItemResponseMessageType responseMessage =
                    response.ResponseMessages.Items[0] as FindItemResponseMessageType;
                    if (responseMessage.ResponseClass != ResponseClassType.Success)

                    messages = (responseMessage.RootFolder.Item as ArrayOfRealItemsType).Items;
                catch (Exception ex)
                    throw new Exception(ex.Message);


    The above code throws 401 - Error in my solution.Please let me know about this issue.

    Tuesday, April 5, 2011 9:57 AM

All replies

  • Hi,

    as I understand your code, you try to access a mailbox using delegation. Have you delegate access on "windowsLiveUserId" account ?


    Désiré GOVIN, Refresh IT Solutions
    Tuesday, April 5, 2011 10:52 AM
  • Hi,

    Thanks for your reply.Please let me know how to give delegate access on "WindowsLiveID" account.

    Tuesday, April 5, 2011 11:09 AM
  • I see in your code 2 IDs : windowsliveid and windowsLiveUserId. Is it a mistake ? If so, you don't need to initialize folder.Mailbox. The submitted credential is enough (line 2 of your code)


    Désiré GOVIN, Refresh IT Solutions
    Tuesday, April 5, 2011 11:59 AM
  • That is Windows Live User Id.It should be something like : , where is our registered domain from Live@edu.
    Tuesday, April 5, 2011 12:14 PM
  • Hi,

     I guess there are 2 cases can be possible:

    1. "windowsliveid" is logon name and  "windowsLiveUserId" is mailbox address for the same user.

     In this case please check that you are providing windowsLiveUserId as complete mailbox address like, 

    2. "windowsliveid" is a logon user and "windowLiveuserId" is different mailbox 

          In this case I suggest you should provide full access permission to user "windowsliveid" for accessing "windowsLiveUserId ".

            and provide windowsLiveUserId as complete mailbox address like, 


    Tejas Suthar Software Engineer
    Wednesday, May 4, 2011 1:23 PM