Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi Outlook, how to add an address in a distribution list (https://www.delphipraxis.net/32127-outlook-how-add-address-distribution-list.html)

Delphi-Lover 19. Okt 2004 09:35


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 can not find an other way to add an address.

Thanks a lot,

Delphi-Lover.

Delphi-Quellcode:
Var obj, Entry, NewMember : OleVariant;
begin
  obj := CreateOleObject('outlook.application');
  obj := obj.GetNameSpace('MAPI');

  //Create an new distribution list
  //AddressList(6) is my personal addressbook
  Entry:=obj.AddressLists(6).AddressEntries.Add('MAPIPDL','New List');
  Entry.Update;

  NewMember:=Entry.members;
  //Error Here:
  NewMember.Add('SMTP','NewName');
End;
[edit=sakura] inserted the [delphi] tags Mfg, sakura[/edit]

fkerber 19. Okt 2004 11:15

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

Welcome in DP

Can you tell us what error it is?

Ciao Frederic

Delphi-Lover 19. Okt 2004 12:20

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

The error message I've to translate to English:

EOLEException:
There is an attempt beiing made to open a non existing property.

Greets,

DL.

Delphi-Lover 21. Okt 2004 10:49

Re: Outlook, how to add an address in a distribution list
 
It seems that I have to answer my own question :-D

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;

Delphi-Lover 28. Okt 2004 15:58

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

If you want to add more members to the Distribution List then use the "myDistList.Save;" AFTER you add ALL the members!

Greets,

Delphi Lover.

Nikolas 28. Okt 2004 16:00

Re: Outlook, how to add an address in a distribution list
 
[OT] Warum unterhaltet ich euch nicht einfach auf deutsch? [/OT]

fkerber 28. Okt 2004 19:49

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

Zitat:

Zitat von Toxman
[OT] Warum unterhaltet ich euch nicht einfach auf deutsch? [/OT]

Vielleich weil der Fragensteller kein Deutsch kann?


Ciao Frederic

Delphi-Lover 1. Nov 2004 09:55

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

Yes, indeed my German is not that good. If you read the source above you can even discover where I'm coming from... Beside this, I see the power of these kind of Forums (where you don't have to pay!) and I think a lot of (Delphi) people all over the world will find on delphipraxis.net the answer on their questions (be Google Bei Google suchen Delphi Lover Outlook friendly!) Especially if the database will grow and grow the coming years. I think they will be very happy if the language is in English. Also all my sources I write are in English. I forced myself to do so, because the IT world is very international and for other programmers it is very difficult to read if sources (variables/comments) are in not English language. Also if you are a professional developer then a lot of other programmers have to work with your sources and companies nowadays take employees from all over the world.

Greets and keep this GREAT :angel: Formum alive! :hi:

Delphi Lover.


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:06 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz