Beispiel #1
0
 public void showAddress(string searchName, Outlook.AddressEntry address, int flag)
 {
     if (address != null)
     {
         // 邮件地址
         if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry)  // 普通地址
         {
             // 普通地址的 searchName 中缺少Email地址 需要另外获取
             this.showSingle(this.i18n[this.lang]["mailAddress"] + ": " + searchName + " " + address.GetExchangeUser().PrimarySmtpAddress, flag);
         }
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookContactAddressEntry) // 存入联系人中的地址
         {
             // 存入联系人中的地址的 searchName 中包含了Email地址 无要另外获取
             this.showSingle(this.i18n[this.lang]["mailAddress"] + ": " + searchName, flag);
         }
         // 组邮件地址
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry) // 普通组地址
         {
             // 普通组地址的 searchName 为组名 Email地址可通过Outlook ExchangeDistributionList 对象获取
             Outlook.ExchangeDistributionList disList = address.GetExchangeDistributionList();
             this.showMuilt(this.i18n[this.lang]["groupMailAddress"] + ": " + searchName + " " + disList.PrimarySmtpAddress, flag);
             this.addAddressNativeGroupList(disList);
         }
         else if (address.AddressEntryUserType == Outlook.OlAddressEntryUserType.olOutlookDistributionListAddressEntry) // 自建组地址
         {
             // 自建组地址的 searchName 为组名 且无Email地址 直接仅显示组名
             this.showMuilt(this.i18n[this.lang]["groupMailAddress"] + ": " + searchName, flag);
             this.addAddressSelfBuildGroupList(address, searchName);
         }
     }
     else
     {
         this.showSingle(searchName, 0);
     }
 }
Beispiel #2
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);
                 }
             }
         }
     }
 }
        public static void DisplayGlobalAddressList()
        {
            DataTable table = new DataTable();

            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("Company", typeof(string));
            table.Columns.Add("Address", typeof(string));

            Outlook.Application outlook = new Outlook.Application();

            Outlook.AddressList gal = outlook.Session.GetGlobalAddressList();

            if (gal != null)
            {
                for (int i = 1; i < gal.AddressEntries.Count - 1; i++)
                {
                    try
                    {
                        Outlook.AddressEntry addressEntry = gal.AddressEntries[i];

                        if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry || addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            Outlook.ExchangeUser exUser = addressEntry.GetExchangeUser();
                            Debug.WriteLine(exUser.Name + "    " + exUser.CompanyName);
                            table.Rows.Add(exUser.Name, exUser.CompanyName, exUser.PrimarySmtpAddress);
                        }

                        if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        {
                            Outlook.ExchangeDistributionList exList = addressEntry.GetExchangeDistributionList();
                            Debug.WriteLine(exList.Name + "   " + exList.PrimarySmtpAddress);
                            table.Rows.Add(exList.Name, "", "");
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }

            ExportCsvUtil.ExportCsv(table, "", "");
        }
Beispiel #4
0
        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);
                            }
                        }
                    }
                }
            }
        }