質問

Currently I'm using Outlook Microsoft.Office.Interop.Outlook.SelectNamesDialog to get Contacts, But in the Address Book (Microsoft.Office.Interop.Outlook.SelectNamesDialog) there are group emails also.

I'm looking for a way to get all the emails in that email group?

役に立ちましたか?

解決

Here is an example on how to retrieve members from an Exchange Distribution List via SelectNamesDialog selection.

Outlook.SelectNamesDialog names =  Globals.ThisAddIn.Application.Session.GetSelectNamesDialog();
names.SetDefaultDisplayMode(Outlook.OlDefaultSelectNamesDisplayMode.olDefaultMembers);
names.ForceResolution = true;
names.Caption = "Please selection something";
if (names.Display())
{
    Outlook.Recipients recipients = names.Recipients;
    foreach (Outlook.Recipient recipient in recipients)
    {
        Outlook.AddressEntry entry = recipient.AddressEntry;
        if (entry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
        {
            Outlook.ExchangeDistributionList list = entry.GetExchangeDistributionList();
            Outlook.AddressEntries members = list.GetExchangeDistributionListMembers();
            foreach (Outlook.AddressEntry member in members)
            {
                Outlook.ExchangeUser user = member.GetExchangeUser();
                string address = user.PrimarySmtpAddress;
            }
        }
    }
}

Once you have the addresses, it would be easily to add them to a collection.

他のヒント

The previous answer will fail for the distribution lists from your Contacts folder. All you need to do is access Recipient.AddressEntry.Members collection (be prepared to handle nulls).

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top