Delphi-Lover
asked on
Outlook, how to add an address in a distribution list
Hello,
I've tried to add a new mailaddress in an addresslist, but I got an error when doing so. I did not find an other way to add an address.
Thanks a lot,
Delphi-Lover.
Var obj, Entry, NewMember : OleVariant;
begin
obj := CreateOleObject('outlook.a pplication ');
obj := obj.GetNameSpace('MAPI');
//Create an new distribution list
//AddressList(6) is my personal addressbook
Entry:=obj.AddressLists(6) .AddressEn tries.Add( 'MAPIPDL', 'New List');
Entry.Update;
NewMember:=Entry.members;
//Error Here:
NewMember.Add('SMTP','NewN ame');
End;
I've tried to add a new mailaddress in an addresslist, but I got an error when doing so. I did not find an other way to add an address.
Thanks a lot,
Delphi-Lover.
Var obj, Entry, NewMember : OleVariant;
begin
obj := CreateOleObject('outlook.a
obj := obj.GetNameSpace('MAPI');
//Create an new distribution list
//AddressList(6) is my personal addressbook
Entry:=obj.AddressLists(6)
Entry.Update;
NewMember:=Entry.members;
//Error Here:
NewMember.Add('SMTP','NewN
End;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
uses ComObj;
procedure AddAddressInDistributionLi
Var myOlApp,
myNameSpace,
myContact,
myDistList,
myMailItem,
myRecipients : OleVariant;
begin
myOlApp:=CreateOleObject('
myNameSpace:=myOlApp.GetNa
//Create the new Contact
myContact:=myOlApp.CreateI
myContact.FullName:='New Name';
myContact.Email1Address:='
myContact.Save;
{
.FirstName:='Delphi';
.LastName:='Lover';
.MobileTelephoneNumber:='1
.HomeAddressStreet:='Delph
.HomeAddressCity:='Amsterd
.HomeAddressState:='NL';
.HomeAddressPostalCode:='1
.Categories:='Business,Per
//More field availble!!
myContact.Display;
}
//Create the Distribution List item
//olDistributionListItem = 7;
//this constant is not in my Outlook API...
myDistList:=myOlApp.Create
myDistList.DLName:='Test Distribution List';
//The MailItem is required to
//create the Recipients collection
myMailItem:=myOlApp.Create
myRecipients:=myMailItem.R
//A Contact with the following e-mail address
//must exist for the AddMembers method to work
myRecipients.Add('username
myRecipients.ResolveAll;
myDistList.AddMembers(myRe
myDistList.Save;
//myDistList.Display;
myContact.Delete;
end;