I'm in a situation where I need to connect to an Exchange server using the following information.
Server URL Email Address Username Password
In an ideal world, I would supply the email and password, and use auto-discover to connect, however, the client does not have auto-discover enabled, and I cannot have the password for security reasons. Currently what I do is run my windows service with windows account that has the permission to connect to the mailbox like:
NetworkCredential credentials = CredentialCache.DefaultNetworkCredentials;
_service.Url = new Uri(_serverURL);
_service.Credentials = credentials;
The issue with this is that if the windows account has more than one mailbox associated with it, it will connect to the first mailbox it finds. I want to be able to connect to the mailbox I specify. Is this possible?
That object doesn't actually connect to the Mailbox and in EWS as its a SOAP service there is no persistent connection. The ExchangeService object holds the connection information so when you make a request like FindFolder, Bind etc it holds the EWS endpoint and credentials to use.
If you want to access another mailbox (other then that of the security credentials you specify in the service object) then you just need to use the Mailbox overload of the FolderId object eg.
FolderId RootFolder = new FolderId(WellKnownFolderName.MsgFolderRoot, "MailboxtoAccess@domain.com");