Пример #1
0
        static void Main(string[] args)
        {
            OutlookUtil outlookUtil = OutlookUtil.GetInstance();

            List<UserAddressBook> testList = new List<UserAddressBook>();

            UserAddressBook test1 = new UserAddressBook()
            {
                UserName = "******",
                Department = "测试部门1",
                Email = "*****@*****.**",
                Mobile = "13800000001",
                SubPhone = "001"
            };

            UserAddressBook test2 = new UserAddressBook()
            {
                UserName = "******",
                Department = "测试部门2",
                Email = "*****@*****.**",
                Mobile = "13800000002",
                SubPhone = "002"
            };

            testList.Add(test1);
            testList.Add(test2);

            Console.WriteLine("将测试数据写入 Outlook 地址簿!");
            outlookUtil.WriteAddressBookList(testList);

            Console.WriteLine("从 Outlook 地址簿读取数据!");
            List<UserAddressBook> newList = outlookUtil.ReadAddressBookList();

            Console.WriteLine("向前面获取的 用户信息,发送电子邮件!");
            outlookUtil.SendMailToUserList(newList);

            Console.WriteLine("处理完毕,按回车键退出!");
            Console.ReadLine();
        }
Пример #2
0
        /// <summary>
        /// 获取 Outlook 地址簿列表.
        /// </summary>
        /// <returns></returns>
        public List<UserAddressBook> ReadAddressBookList()
        {
            List<UserAddressBook> resultList = new List<UserAddressBook>();

            Outlook.NameSpace mynamespace = outlookApp.GetNamespace("MAPI");
            Outlook.MAPIFolder myFolder = mynamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
            int iMailCount = myFolder.Items.Count;

            for (int k = 1; k <= iMailCount; k++)
            {
                Outlook.ContactItem item = (Outlook.ContactItem)myFolder.Items[k];

                UserAddressBook result = new UserAddressBook();

                // 姓名.
                result.UserName = item.LastName;

                // 邮件地址.
                result.Email = item.Email1Address;

                // 号码.
                result.Mobile = item.MobileTelephoneNumber;

                // 部门.
                result.Department = item.Department;

                // 加入列表.
                resultList.Add(result);
            }

            return resultList;
        }