目前我正在使用 OutlookMicrosoft.Office.Interop.Outlook.SelectNamesDialog
获取联系人,但在通讯簿( Microsoft.Office.Interop.Outlook.SelectNamesDialog
) 中也有群组电子邮件。
我正在寻找一种方法来获取该电子邮件组中的所有电子邮件?
对于您的联系人文件夹中的通讯组列表,上一个答案将失败。您需要做的就是访问 Recipient.AddressEntry.Members 集合(准备好处理空值)。
以下是有关如何通过选择从Exchange 分发列表中检索成员的示例。SelectNamesDialog
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;
}
}
}
}
一旦你有了地址,就很容易将它们添加到集合中。