示例#1
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);
        }
示例#2
0
        ActionOutput <RecipientDetails> IAddressBookManager.AddUpdateAddressBook(AddUpdateRecipientModel model)
        {
            var message = "";
            RecipientDetails addressDetails = new RecipientDetails();

            if (model.ID > 0)
            {
                var existngUser = Context.UserAddressBooks.Where(z => z.Name.Trim().ToLower() == model.Name.Trim().ToLower() && z.Address == model.Address && z.UserIDFK == model.UserID && z.ID != model.ID &&
                                                                 z.IsDeleted == false).FirstOrDefault();
                if (existngUser != null)
                {
                    return(new ActionOutput <RecipientDetails>
                    {
                        Status = ActionStatus.Error,
                        Message = "This author with same name and address is already added into your address book."
                    });
                }

                var address = Context.UserAddressBooks.Where(z => z.ID == model.ID && z.IsDeleted != true).FirstOrDefault();
                address = Mapper.Map <AddUpdateRecipientModel, UserAddressBook>(model, address);
                address.AddressVerified = model.AddressVerified;
                Context.SaveChanges();
                message = "Address details updated successfully.";
            }
            else
            {
                var existngUser = Context.UserAddressBooks.Where(z => z.Name.Trim().ToLower() == model.Name.Trim().ToLower() && z.Address == model.Address && z.UserIDFK == model.UserID && z.IsDeleted != true && z.IsPermanent == true).FirstOrDefault();
                if (existngUser != null)
                {
                    return(new ActionOutput <RecipientDetails>
                    {
                        Status = ActionStatus.Error,
                        Message = "This recipient with same name and address is already added into your address book."
                    });
                }
                else
                {
                    UserAddressBook book = Mapper.Map <AddUpdateRecipientModel, UserAddressBook>(model);
                    book.IsActive    = true;
                    book.ActivatedOn = DateTime.UtcNow;
                    book.AddedOn     = DateTime.UtcNow;
                    book.IsDeleted   = false;
                    Context.UserAddressBooks.Add(book);
                    Context.SaveChanges();
                    addressDetails = Mapper.Map <UserAddressBook, RecipientDetails>(book, addressDetails);
                    //  recipientDetails.State = Context.states.FirstOrDefault(x => x.id == book.State).name;
                    //                    recipientDetails.City = Context.cities.FirstOrDefault(x => x.cityID == book.City).cityName;
                    message = "Address details added successfully.";
                }
            }
            return(new ActionOutput <RecipientDetails>
            {
                Status = ActionStatus.Successfull,
                Message = message,
                Object = addressDetails
            });
        }
示例#3
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();
        }
示例#4
0
        //private string[] addressBookColumnNames = new string[] { "Category", "Sub- Category", "Author", "Keyword Famous For (Book, Song, Award, Distinct)",
        //    "Agency","Address Line 1", "City", "State", "Zip", "Country", "Address Verified (Yes / no / Maybe)","ImageLink" };

        ActionOutput <DataTable> IAddressBookManager.SaveAddressesImportExcel(DataSet ds, int userId)
        {
            DataTable dt = new DataTable("Grid");

            foreach (var item in ds.Tables[0].Columns)
            {
                if (!item.ToString().Contains("Column"))
                {
                    dt.Columns.Add(new DataColumn(item.ToString()));
                }
            }

            try
            {
                //var checkInvalidColumnName = ContainColumnThenGetData(ref ds);

                //if (!string.IsNullOrEmpty(checkInvalidColumnName))
                //    return new ActionOutput<DataTable>() { Status = ActionStatus.Error, Message = "Error Invalid column name occured " + checkInvalidColumnName + "." };

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

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    var name    = ds.Tables[0].Rows[i][2].ToString();
                    var address = ds.Tables[0].Rows[i][5].ToString();

                    var existngUser = Context.UserAddressBooks.Where(z => z.Name.Trim().ToLower() == name.Trim().ToLower() && z.Address == address && z.UserIDFK == userId && z.IsDeleted != true && z.IsPermanent == true).FirstOrDefault();
                    if (existngUser != null)
                    {
                        continue;
                    }

                    var model = new UserAddressBook();

                    model.UserIDFK         = userId;
                    model.Category         = ds.Tables[0].Rows[i][0].ToString();
                    model.SubCategory      = ds.Tables[0].Rows[i][1].ToString();
                    model.Name             = ds.Tables[0].Rows[i][2].ToString();
                    model.KeywordFamousFor = ds.Tables[0].Rows[i][3].ToString();
                    model.Agency           = ds.Tables[0].Rows[i][4].ToString();
                    model.Address          = ds.Tables[0].Rows[i][5].ToString();
                    model.City             = ds.Tables[0].Rows[i][6].ToString();
                    model.State            = ds.Tables[0].Rows[i][7].ToString();
                    model.Zip       = ds.Tables[0].Rows[i][8].ToString();
                    model.Country   = ds.Tables[0].Rows[i][9].ToString();
                    model.ImageLink = Convert.ToString(ds.Tables[0].Rows[i][11]);
                    var addressVerified = ds.Tables[0].Rows[i][10].ToString();

                    if (addressVerified.Trim().ToLower() == "Yes".Trim().ToLower())
                    {
                        model.AddressVerified = true;
                    }
                    else
                    {
                        model.AddressVerified = false;
                    }

                    model.IsActive     = true;
                    model.IsDeleted    = false;
                    model.IsPermanent  = true;
                    model.ActivatedOn  = DateTime.UtcNow;
                    model.AddedOn      = DateTime.UtcNow;
                    model.AddedByAdmin = true;

                    if (!string.IsNullOrEmpty(model.Name) && !string.IsNullOrEmpty(model.Address) && !string.IsNullOrEmpty(model.Country) &&
                        !string.IsNullOrEmpty(model.State) && !string.IsNullOrEmpty(model.City))
                    {
                        obj.Add(model);
                    }
                    else
                    {
                        dt.Rows.Add(model.Category, model.SubCategory, model.Name, model.KeywordFamousFor, model.Agency, model.Address,
                                    model.City, model.State, model.Zip, model.Country, model.AddressVerified);
                    }
                }

                if (obj.Count > 0)
                {
                    Context.UserAddressBooks.AddRange(obj);
                    SaveChanges();
                }

                return(new ActionOutput <DataTable>()
                {
                    Status = ActionStatus.Successfull, Object = dt
                });
            }
            catch (Exception e)
            {
                return(new ActionOutput <DataTable>()
                {
                    Status = ActionStatus.Error, Message = e.Message
                });
            }
        }