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