Search code examples
c#.netexchangewebservicesimpersonation

Enumerating accounts you have permissions to impersonate using EWS Managed API


I set up impersonation to allow me to impersonate and access another account on my ExchangeService client object:

var client = new ExchangeService();
client.Credentials = new WebCredentials("account.one@somewhere.com", "password");
client.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
client.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "account.two@somewhere.com");

This works great, however...in my situation, account.one@somewhere.com does not know who they are able to impersonate. How can I enumerate through all of the other accounts they are able to impersonate? I tried searching for an example but I could not find anything.


Solution

  • There is nothing in EWS that will give you that information and it really depends how you have setup impersonation. Eg Impersonation could be configured per user, group or for every recipient in a tenant.

    If your going to constrain Impersonation and you want to enumerate that constraint then using a Mail Enabled security group, enable impersonation for members of the group and then use ExpandGroup in EWS will give you the SMTPAddresses of the members of the group.