Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EWS Managed API: Searching an Inbox other than the main mailbox associated with Windows login

I have an application extracting emails from 'User A', with the email address [email protected]. I use the following code to do so:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.UseDefaultCredentials = true;
service.Url = new Uri(ServerName);

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new  ItemView(500));

This works fine if User A is logged in and runs the application.

However, lets say 'User B' has been granted access to User A's inbox and wants to run the same application to extract files from User A's Inbox. How would I change the code above to specify the email account inbox?

I know that I could hardcode the login details of User A when getting the credentials, but ideally I would avoid having hardcoded usernames but instead use the credentials of the user running the application.

This may just be my lack of understanding, but I'm relatively new to .net and very new to EWS. Any pointers would be much appreciated!

Thanks

like image 414
David Avatar asked Apr 19 '12 16:04

David


1 Answers

Delegation is what I needed:

FolderId InboxId = new FolderId(WellKnownFolderName.Inbox, "[email protected]");
FindItemsResults<Item> findResults = service.FindItems(InboxId, new ItemView(500));
like image 187
David Avatar answered Oct 19 '22 11:10

David