Wrong mailbox items being retrieved using Exchange Web Services managed API in C#

后端 未结 2 1160
醉酒成梦
醉酒成梦 2020-12-14 03:53

I\'m trying to retrieve Inbox items from a specific mailbox (in which i have permissions), using Exchange Web Services managed API. I\'ve tested the code first using my own

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 04:43

    The e-mail address given to AutodiscoverUrl has nothing to do with which mailbox you are binding to.

    There are (at least) two ways to get the inbox items from another users mailbox: Delegate access and impersonation.

    If you have delegate access to the other users mailbox, you can specify the mailbox as a parameter in the call to FindItems:

    FindItemsResults findResults = ex.FindItems(
        new FolderId(WellKnownFolderName.Inbox, new Mailbox("someothermailbox@company.com")), 
        new ItemView(10));
    

    If you have the permissions to impersonate the other user, you can impersonate the other user when connecting to the EWS and the following call to FindItem will work on the inbox of the impersonated user:

    ExchangeService ex = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
    ex.AutodiscoverUrl("someothermailbox@company.com");
    ex.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "someothermailbox@company.com");
    ItemsResults findResults = ex.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
    

    Disclaimer: I have written the above code without actually testing it on a real Exchange server.

提交回复
热议问题