Search code examples
outlookmicrosoft-graph-apiexchange-servercom-interopwin32com

How do I get the memberships (distribution groups) of an Outlook contact programmatically?


Using office Outlook, we can find the 'Memberships' tab when we click and expand a contact, this 'Memberships' tab shows the list of emails that the user is subscribed to.

For example, Employee X (x.x@zcompany.com / id123@zcompany.com) under the Data Department of Z Company is subscribed to the following distribution groups:

  • datateam@zcompany.com
  • allemployeees@zcompany.com
  • dataweekly@zcompany.com
  • it.uk@zcompany.com
  • znewsletter@zcompany.com

I would like to get the list of emails the user is subscribed to by inputting either the user's email or user's organization ID.

I found a few potential solutions but do not know exactly how to implement them:

  1. Outlook Interop GetMemberOfList() and GetExchangeDistributionList()
  2. Using Microsoft Graph API
  3. VBA automation for Outlook
  4. Reverse engineering using ExchangePowershell
  5. Using RPA to imitate user actions on Outlook

Wonder if someone with experience doing this can provide some advice? Thanks in advance.


Solution

  • In OOM, call Application.Session.CreateRecipient, Recipient.Resolve, Recipient.AddressEntry.GetExchangeUser(). ExchangeUser exposes GetMemberOfList() method, which returns IAddressEntries object.