Ejemplo n.º 1
0
        private Dictionary <string, string> ObterListaContatosOutlook()
        {
            Dictionary <string, string> lista = new Dictionary <string, string>();

            try
            {
                Outlook.Application outlook  = new Outlook.Application();
                Outlook.AddressList contatos = outlook.Session.GetGlobalAddressList();

                lista.Clear();
                foreach (Outlook.AddressEntry item in contatos.AddressEntries)
                {
                    Outlook.ExchangeUser contato = item.GetExchangeUser();
                    if (contato != null)
                    {
                        lista.Add(contato.Name.ToUpper(), contato.PrimarySmtpAddress);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Obter Lista Contatos Outlook: " + ex.Message);
            }
            return(lista);
        }
Ejemplo n.º 2
0
        public IdFinder(Person p)
        {
            ApplicationCreator applicationCreator = new ApplicationCreator();

            outlookApp = applicationCreator.GetOutlookApplication();

            globalAddressList = outlookApp.Session.GetGlobalAddressList();
            person            = p;
        }
Ejemplo n.º 3
0
 private void a()
 {
     Outlook.AddressList gal = _application.Session.GetGlobalAddressList();
     foreach (Outlook.AddressEntry address in gal.AddressEntries)
     {
         //if (address.AddressEntryUserType == OlAddressEntryUserType.olExchangeUserAddressEntry)
         //{
         //    address
         //}
     }
 }
Ejemplo n.º 4
0
        //Получает все учетные записи с почты.
        private void EnumerateGAL()
        {
            try
            {
                Outlook.Application app = new Outlook.Application();
                Outlook.NameSpace   ns  = app.GetNamespace("MAPI");
                ns.Logon("", "", false, true);

                Outlook.AddressList gal = ns.Session.GetGlobalAddressList();
                progressBar1.Maximum = gal.AddressEntries.Count;
                if (gal != null)
                {
                    int n = 1;
                    for (int i = 1; i <= gal.AddressEntries.Count; i++)
                    {
                        Outlook.AddressEntry addrEntry = gal.AddressEntries[i];
                        if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
                            addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
                        {
                            Outlook.ExchangeUser exchUser = addrEntry.GetExchangeUser();
                            Program.UpdataUsers.Add(exchUser.Name, exchUser.PrimarySmtpAddress);
                            progressBar1.Value = i;
                        }
                        #region один логин выпадает там
                        //if (addrEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeDistributionListAddressEntry)
                        //{
                        //    Outlook.ExchangeDistributionList exchDL = addrEntry.GetExchangeDistributionList();
                        //    //MessageBox.Show(exchDL.Name + " " + exchDL.PrimarySmtpAddress);
                        //        using (StreamWriter sw = new StreamWriter(nameUsers2, true, System.Text.Encoding.Default))
                        //        {
                        //            sw.WriteLine("2 file: " + exchDL.Name + " - " + exchDL.PrimarySmtpAddress);
                        //        }
                        //    progressBar1.Value = i;
                        //}
                        #endregion
                        n++;
                    }
                    if (n > gal.AddressEntries.Count)
                    {
                        progressBar1.Value = 0;
                    }
                    Close();
                }
            }
            catch (Exception e) { MessageBox.Show(e.Message); }
        }
Ejemplo n.º 5
0
        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, "", "");
        }
Ejemplo n.º 6
0
        private void LoadContactsList()
        {
            Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

            Outlook.Folder contactsFolder = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders) as Outlook.Folder;

            Outlook.Folder currentFolder = outlookApp.ActiveExplorer().CurrentFolder as Outlook.Folder;
            Outlook.Store  currentStore  = currentFolder.Store;

            Outlook.AddressList    addressList = this.GetGlobalAddressList(outlookApp, currentStore);
            Outlook.AddressEntries entries     = addressList.AddressEntries;

            this._contactsList = new List <Contact>();

            foreach (Outlook.AddressEntry entry in entries)
            {
                Outlook.ExchangeDistributionList distList = entry.GetExchangeDistributionList();
                Outlook.ExchangeUser             user     = entry.GetExchangeUser();
                Outlook.ContactItem contact = entry.GetContact();

                if (distList != null)
                {
                    this._contactsList.Add(new Contact(distList.Name, distList.PrimarySmtpAddress));
                }

                if (contact != null)
                {
                    this._contactsList.Add(new Contact(contact.FirstName + " " + contact.LastName, contact.IMAddress));
                }

                if (user != null)
                {
                    if (user.FirstName == null && user.LastName == null)
                    {
                        this._contactsList.Add(new Contact(user.Name, user.PrimarySmtpAddress));
                    }
                    else
                    {
                        this._contactsList.Add(new Contact(user.FirstName + " " + user.LastName, user.PrimarySmtpAddress));
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// ListViewのアイテムをリフレッシュする
        /// </summary>
        public void RefreshContactList()
        {
            if (ExchangeUserItem == null)
            {
                return;
            }

            lstSuperiors.Clear();
            lviAllItem.Clear();

            // 接続状況の判定
            if (Globals.ThisAddIn.Application.Session.Offline)
            {
                // Exchangeに接続していない
                // 「Offline Global Address List」を取得

                MessageBox.Show("Application.Session.Offline = true  オフライン");

                foreach (Outlook.AddressList list in Globals.ThisAddIn.Application.Session.AddressLists)
                {
                    if (list.AddressListType.ToString() != "olExchangeGlobalAddressList")   // 該当のアドレス一覧名はべた書き。。。
                    {
                        continue;
                    }

                    foreach (Outlook.AddressEntry entryItem in list.AddressEntries)
                    {
                        Outlook.ExchangeUser checkItem = entryItem.GetExchangeUser();

                        if (checkItem != null)
                        {
                            if (string.IsNullOrEmpty(checkItem.CompanyName) == false)
                            {
                                if (checkItem.CompanyName.Contains(ExchangeUserItem.CompanyName) != false)
                                {
                                    string name       = checkItem.LastName + " " + checkItem.FirstName;
                                    string department = checkItem.Department;
                                    string position   = checkItem.JobTitle;

                                    ListViewItem lvi = new ListViewItem();
                                    lvi.ImageKey = checkItem.Name;
                                    lvi.Name     = checkItem.PrimarySmtpAddress;
                                    lvi.Text     = name;
                                    lvi.SubItems.Add(department);
                                    lvi.SubItems.Add(position);
                                    lviAllItem.Add(lvi);

                                    int Index = GetManagerIndex(position);
                                    if (Index != -1)
                                    {
                                        lstSuperiors.Add(lvi);
                                    }
                                    else
                                    {
                                        if (!commonSettingFlg)
                                        {
                                            // 共通設定ファイル読み込み失敗
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                // Exchangeに接続している
                // グローバルアドレス一覧を取得

                MessageBox.Show("Application.Session.Offline = false  オンライン");

                Outlook.AddressList list = Globals.ThisAddIn.Application.Session.GetGlobalAddressList();
                foreach (Outlook.AddressEntry entryItem in list.AddressEntries)
                {
                    Outlook.ExchangeUser checkItem = entryItem.GetExchangeUser();
                    if (checkItem != null)
                    {
                        if (string.IsNullOrEmpty(checkItem.CompanyName) == false)
                        {
                            if (checkItem.CompanyName.Contains(CurrentContactItem.CompanyName) != false)
                            {
                                string name       = checkItem.LastName + " " + checkItem.FirstName;
                                string department = checkItem.Department;
                                string position   = checkItem.JobTitle;

                                ListViewItem lvi = new ListViewItem();
                                lvi.ImageKey = checkItem.Name;
                                lvi.Name     = checkItem.PrimarySmtpAddress;
                                lvi.Text     = name;
                                lvi.SubItems.Add(department);
                                lvi.SubItems.Add(position);
                                lviAllItem.Add(lvi);

                                int Index = GetManagerIndex(position);
                                if (Index != -1)
                                {
                                    lstSuperiors.Add(lvi);
                                }
                                else
                                {
                                    if (!commonSettingFlg)
                                    {
                                        // 共通設定ファイル読み込み失敗
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //foreach (Outlook.AddressList list in Globals.ThisAddIn.Application.Session.AddressLists)
            //{
            //    foreach (Outlook.AddressEntry entryItem in list.AddressEntries)
            //    {
            //        Outlook.ContactItem checkItem = entryItem.GetContact();
            //        if (checkItem != null)
            //        {
            //            if (string.IsNullOrEmpty(checkItem.CompanyName) == false)
            //            {
            //                if (checkItem.CompanyName.Contains(CurrentContactItem.CompanyName) != false)
            //                {
            //                    string name = checkItem.FullName;
            //                    string department = checkItem.Department;
            //                    string position = checkItem.JobTitle;

            //                    ListViewItem lvi = new ListViewItem();
            //                    lvi.ImageKey = checkItem.Email1DisplayName;
            //                    lvi.Name = checkItem.Email1Address;
            //                    lvi.Text = name;
            //                    lvi.SubItems.Add(department);
            //                    lvi.SubItems.Add(position);
            //                    lviAllItem.Add(lvi);

            //                    int Index = GetManagerIndex(position);
            //                    if (Index != -1)
            //                    {
            //                        lstSuperiors.Add(lvi);
            //                    }
            //                    else
            //                    {
            //                        if (!commonSettingFlg)
            //                        {
            //                            // 共通設定ファイル読み込み失敗
            //                            return;
            //                        }
            //                    }
            //                }
            //            }
            //        }
            //    }
            //}

            // 許可者リストにする
            SetSuperiorsList("");
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="addressList"></param>
 public AddressBookProviderOM(Outlook.AddressList addressList)
 {
     _addressList = addressList;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="addressList"></param>
 public AddressBookProviderOM(Outlook.AddressList addressList)
 {
     _addressList = addressList;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="addressList"></param>
 public OLAddressList(Outlook.AddressList addressList)
 {
     _addressList = addressList;
 }