プログラムでOutlook連絡先と通信グループを追加

1981 ワード

       Outlook         。    ,Outlook        ,          
  IClassFactory   CLSID   {0006F03A-0000-0000-C000-000000000046}   COM         ,         : 8001010a。
           
                OL.Application app = new OL.ApplicationClass();


                OL.DistListItem dist = (OL.DistListItem)app.CreateItem(OL.OlItemType.olDistributionListItem);
                dist.Subject = group;

                foreach (var contact in contacts)
                {
                    OL.ContactItem item = (OL.ContactItem)app.CreateItem(OL.OlItemType.olContactItem);
                    //item.FirstName = "ares";//  
                    //item.LastName = "chen";// 

                    item.LastName = contact.Name.Substring(0, 1);
                    item.FirstName = contact.Name.Substring(1);
                    

                    item.FullName = contact.Name;//    
                    item.CompanyName = contact.CompanyName;//    
                    item.Email1Address = contact.Email;
                    item.Save();

                    OL.Recipient r = app.Session.CreateRecipient(item.FullName);
                    OL.Recipient r2 = app.Session.CreateRecipient(item.Email1Address);

                    r.Resolve();
                    r2.Resolve();

                    if (r.Address == r2.Address)
                        dist.AddMember(r);
                    else
                        dist.AddMember(r2);


                }
                dist.Save();