private void btnFromOutlook_Click(object sender, RoutedEventArgs e) { _seenDLs = new List <Outlook.AddressEntry>(); lstMembers.Items.Clear(); Outlook.SelectNamesDialog snd = _outlook.Session.GetSelectNamesDialog(); Outlook.AddressLists addrLists = _outlook.Session.AddressLists; foreach (Outlook.AddressList addrList in addrLists) { if (addrList.Name == "All Groups") { 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) { EnumerateDL(addrEntry); } } // TODO: /facepalm :( txtTotalMembers.Text = "Total Members: " + lstMembers.Items.Count; }
/// <summary> /// Get the recipient dialog and allow the user to chose a recipient /// </summary> /// <param name="PstrRecipient"></param> public static ExtendedRecipientList GetRecipients(string PstrRecipient = "") { try { Outlook.SelectNamesDialog LobjSnd = Globals.ThisAddIn.Application.Session.GetSelectNamesDialog(); if (PstrRecipient != string.Empty) { LobjSnd.Recipients.Add(PstrRecipient); } LobjSnd.NumberOfRecipientSelectors = Outlook.OlRecipientSelectors.olShowTo; LobjSnd.AllowMultipleSelection = false; LobjSnd.Display(); if (!LobjSnd.Recipients.ResolveAll()) { return(null); } else { return(LobjSnd.Recipients.ToListOfExtendedRecipient()); } } catch (Exception PobjEx) { PobjEx.Log(true, "There was an error selecting the recipient."); return(null); } }
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 BtnChangeTestAddress_Click(object sender, EventArgs e) { string sNewTestEmailAddress = string.Empty; Outlook.SelectNamesDialog oDialog = Globals.ThisAddIn.Application.Session.GetSelectNamesDialog(); oDialog.InitialAddressList = Globals.ThisAddIn.Application.Session.GetGlobalAddressList(); oDialog.AllowMultipleSelection = false; oDialog.Display(); if (oDialog.Recipients.Count <= 0) { return; } Outlook.ExchangeUser exchangeUser = null; try { foreach (Outlook.Recipient recip in oDialog.Recipients) { try { if (exchangeUser != null) { sNewTestEmailAddress += exchangeUser.PrimarySmtpAddress; } else { sNewTestEmailAddress = oDialog.Recipients[1].Address; } sNewTestEmailAddress += ';'; } catch (System.Exception) { throw; } finally { exchangeUser = null; exchangeUser = recip.AddressEntry.GetExchangeUser(); } } } catch (System.Exception) { throw; } finally { oDialog = null; exchangeUser = null; this.sTestEmailAddress = sNewTestEmailAddress; //COMMENT TEST FOR GITHUB //COMMENT TEST FOR LIVE SHARE!!! 🎯 MessageBox.Show(string.Format("The test mode email address has been changed to \n\n{0}\n\nTo set another test email address, use the button at the top right.", this.sTestEmailAddress), this.Text, MessageBoxButtons.OK); } }