public void GetDistributionListMembers(string addlistname, DataGridView dgv) { Outlook.SelectNamesDialog snd = app.Session.GetSelectNamesDialog(); Outlook.AddressLists addrLists = app.Session.AddressLists; foreach (Outlook.AddressList addrList in addrLists) { if (addrList.Name == addlistname) { snd.InitialAddressList = addrList; break; } } snd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo; snd.ToLabel = "D/L"; snd.ShowOnlyInitialAddressList = true; snd.AllowMultipleSelection = false; snd.Display(); if (snd.Recipients.Count > 0) { Outlook.AddressEntry addrEntry = snd.Recipients[1].AddressEntry; if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType. olExchangeDistributionListAddressEntry) { Outlook.ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList(); Outlook.AddressEntries addrEntries = exchDL.GetExchangeDistributionListMembers(); if (addrEntries != null) { foreach (Outlook.AddressEntry exchDLMember in addrEntries) { DataGridViewRow dgvr = new DataGridViewRow(); dgvr.CreateCells(dgv); dgvr.Cells[0].Value = exchDLMember.Name; dgvr.Cells[1].Value = exchDLMember.Address; dgv.Rows.Add(dgvr); // Debug.WriteLine(exchDLMember.Name); } } } } }
private void EnumerateDL(Outlook.AddressEntry dl, string prefix = "") { if (AlreadyEnumeratedDL(dl)) { System.Diagnostics.Debug.WriteLine(prefix + dl.Name + "> <skipping nested dl>"); } else { _seenDLs.Add(dl); Outlook.ExchangeDistributionList exchDL = dl.GetExchangeDistributionList(); Outlook.AddressEntries addrEntries = exchDL.GetExchangeDistributionListMembers(); if (addrEntries != null) { foreach (Outlook.AddressEntry exchDLMember in addrEntries) { if (exchDLMember.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry) { EnumerateDL(exchDLMember, prefix + dl.Name + " > "); } else { var entry = prefix + dl.Name + " > " + exchDLMember.Name; System.Diagnostics.Debug.WriteLine(entry); lstMembers.Items.Add(entry); if (exchDLMember.Address == _currentUser.Address) { MessageBox.Show("Found You!\n\n" + entry); } } } } } }
public void addAddressNativeGroupList(Outlook.ExchangeDistributionList disList) // 普通组邮件成员list添加到addressList区存储 { Outlook.AddressEntries addressEntries = disList.GetExchangeDistributionListMembers(); this.addressList.Add(addressEntries); }