Einzelnen Beitrag anzeigen

Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#4

Re: Outlook, how to add an address in a distribution list

  Alt 21. Okt 2004, 11:49
It seems that I have to answer my own question

To add a contact in a DistributionList you can use an AddMember function. The only disadvantage is that the contact added must be in your contactlist already. So the following code creates first the contact and then add the contact to the DistributionList. I don't need the contact after, so at the end I just delete the contact. (It seems the addmember makes a COPY of the contact in the DistributionList)

Greetings,

Delphi-Lover.

Delphi-Quellcode:
uses ComObj;

procedure AddAddressInDistributionList;
Var myOlApp,
    myNameSpace,
    myContact,
    myDistList,
    myMailItem,
    myRecipients : OleVariant;
begin
   myOlApp:=CreateOleObject('outlook.application');
   myNameSpace:=myOlApp.GetNameSpace('MAPI');

   //Create the new Contact
   myContact:=myOlApp.CreateItem(olContactItem);
   myContact.FullName:='New Name';
   myContact.Email1Address:='username@domain.com';
   myContact.Save;
   {
  .FirstName:='Delphi';
  .LastName:='Lover';
  .MobileTelephoneNumber:='123456');
  .HomeAddressStreet:='Delphi Lane 9';
  .HomeAddressCity:='Amsterdam';
  .HomeAddressState:='NL';
  .HomeAddressPostalCode:='1968';
  .Categories:='Business,Personal';
  //More field availble!!
  myContact.Display;
   }


   //Create the Distribution List item
   //olDistributionListItem = 7;
   //this constant is not in my Outlook API...
   myDistList:=myOlApp.CreateItem(7);
   myDistList.DLName:='Test Distribution List';

   //The MailItem is required to
   //create the Recipients collection
   myMailItem:=myOlApp.CreateItem(olMailItem);
   myRecipients:=myMailItem.Recipients;

   //A Contact with the following e-mail address
   //must exist for the AddMembers method to work
   myRecipients.Add('username@domain.com');
   myRecipients.ResolveAll;
   myDistList.AddMembers(myRecipients);
   myDistList.Save;
   //myDistList.Display;

   myContact.Delete;
end;
Rob
  Mit Zitat antworten Zitat