문제

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