none
Reading Inbox without account RRS feed

  • Question

  • Hi,

    I am creating a windows service that is reading different inboxes. To read them I use this (abbreviated) code:

     

    ItemView view = new ItemView(100);

    string mailbox = "user1@domain.com";

    ExchangeService eService= new ExchangeService(ExchangeVersion.Exchange2013, TimeZoneInfo.Utc);
    eService.Credentials = new WebCredentials(CredentialCache.DefaultCredentials);

    FindItemsResults<Item> result = eService.FindItems(new FolderId(WellKnownFolderName.Inbox, mailbox), view);

     

    When I debug this using my credentials (dev1) all works fine, but as soon as I install it as a windows service running as user 'serv1' I get the following error: 

    Microsoft.Exchange.WebServices.Data.ServiceResponseException: When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.

     

    user1 has a mailbox (the one I am trying to read). I (dev1) have one as well, serv1 does NOT have a mailbox and 'mailbox' is set to the primary SMTP address of user1. I did some research and found that I should use Impersonation, so I add:

    eService.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailbox);

    before calling FindItems. Which again works fine when debugging under my id, but the service now fails with:

     

    Microsoft.Exchange.WebServices.Data.ServiceResponseException: The SMTP address has no mailbox associated with it.

     

    Does that mean the user that authenticates to Exchange needs an account to be able to read other Inboxes? Or am I missing something in my code?

    thanks

    -dieter




    • Edited by eurdip Wednesday, January 22, 2014 7:10 PM
    Wednesday, January 22, 2014 7:07 PM

All replies

  • serv1  should have mailbox access over the user1 account. Until the account that you are using in script should have proper mailbox permission on the mailbox that needs to be connected. Or else you will not able access the user mailbox.

    Exchange Queries

    Wednesday, January 22, 2014 10:13 PM
  • It should have. The exchange admin confirmed that it does. I also use Outlook to just monitor the Inbox. I can logon to a PC as serv1 and use Outlook to control user1 Inbox without problems
    Thursday, January 23, 2014 1:02 PM
  • Here is what worked for us:

    We tried impersonation, but that didn't seem to make a difference. Then we found this blog:

    http://blogs.msdn.com/b/mstehle/archive/2013/07/25/more-affinity-considerations-for-exchange-online-and-exchange-2013.aspx

    and

    eService.HttpHeaders.Add("X-AnchorMailbox", mailbox);

    did the trick

    Tuesday, February 4, 2014 5:38 PM