Example #1
0
 /// <summary>
 /// 从OutLook中取出用户
 /// </summary>
 /// <param name="fields"></param>
 /// <param name="ds"></param>
 /// <returns></returns>
 public static Boolean getMailAddressFromOUTLOOK(string[] fields, ref DataSet ds)
 {
     try
     {
         // Create the Outlook application.
         Outlook.Application oApp = new Outlook.Application();
         //Get the MAPI namespace.
         Outlook.NameSpace oNS = oApp.Session;
         //Get the AddressLists collection.
         Outlook.AddressLists oALs = oNS.AddressLists;
         //Loop through the AddressLists collection.
         Outlook.AddressList oAL;
         for (int i = 1; i <= oALs.Count; i++)
         {
             oAL = (Outlook.AddressList)oALs.GetEnumerator().Current;
             //
             oALs.GetEnumerator().MoveNext();
         }
     }//end of try block
     catch (System.Exception ex)
     {
         NCLogger.GetInstance().WriteExceptionLog(ex);
         return(false);
         //MessageBox.Show("outllok " + ex.Message);
     } //end of catch
     return(true);
 }     //end of Email Method
Example #2
0
        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;
        }
Example #3
0
 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);
                 }
             }
         }
     }
 }
Example #4
0
 public void cbinitAddLists(ComboBox cb)
 {
     Outlook.AddressLists addrLists =
         app.Session.AddressLists;
     foreach (Outlook.AddressList addrList in addrLists)
     {
         try
         {
             if (addrList.AddressEntries.Count > 0)
             {
                 cb.Items.Add(addrList.Name);
             }
         }
         catch (Exception)
         {
             continue;
         }
     }
 }
Example #5
0
        public void dgvAddEmailUsername(DataGridView dgv, string addname)
        {
            Outlook.AddressLists addrLists =
                app.Session.AddressLists;

            var myFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);

            foreach (Outlook.AddressList addrList in addrLists)
            {
                if (addrList.Name.Equals(addname))
                {
                    foreach (Outlook.AddressEntry item in addrList.AddressEntries)
                    {
                        if (item.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry)
                        {
                            Outlook.ExchangeUser exuser = item.GetExchangeUser();
                            DataGridViewRow      dgvr   = new DataGridViewRow();
                            dgvr.CreateCells(dgv);
                            dgvr.Cells[0].Value = exuser.Name;
                            dgvr.Cells[1].Value = exuser.PrimarySmtpAddress;
                            dgv.Rows.Add(dgvr);
                        }
                        else if (item.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookContactAddressEntry)
                        {
                            Outlook.ContactItem exuser = item.GetContact();
                            DataGridViewRow     dgvr   = new DataGridViewRow();
                            dgvr.CreateCells(dgv);
                            dgvr.Cells[0].Value = exuser.FullName;
                            dgvr.Cells[1].Value = exuser.Email1Address;
                            dgv.Rows.Add(dgvr);
                        }
                    }
                    break;
                }
            }
        }