![]() |
Outlook: Prüfen, ob Kontakt Mailadresse hat
Hallo,
ich möchte in meinem Programm die Kontakte (Namen und Mailadressen) aus Outlook auslesen und in einem Grid darstellen. Allerdings möchte ich nur die Kontakte darstellen, die eine Mailadresse haben. Wenn ich allerdings mit
Delphi-Quellcode:
prüfe, erhalte ich die Meldung "Ungültige Variant-Operation" bei "if Contact.Email1Adress = ''". Die Prüfung auf Length = 0 bringt den gleichen Fehler.. :?:
outlook := CreateOleObject('Outlook.Application');
NameSpace := outlook.GetNameSpace('MAPI'); Contacts := NameSpace.GetDefaultFolder(olFolderContacts); for i := 1 to Contacts.Items.Count do begin if Contact.Email1Address = '' then showmessage('keine Adresse'); .... Wie kann ich denn feststellen, ob im Feld "Email1Adress" von Outlook etwas eingetragen ist? Gruß Frank |
Re: Outlook: Prüfen, ob Kontakt Mailadresse hat
In deinem Code taucht auf einmal "Contact" auf. :)
Hast du das gesetzt?
Delphi-Quellcode:
Der zweite Punkte ist, dass Outlook dir in dem Array der Kontakte nicht nur einzelne Kontakte, sondern auch Gruppen von Kontakten zurückgibt.
Contact := Contacts.Items[i];
Dieses Objekt hat dieEigenschaft "Email1Address" nicht. Du musst zuerst prüfen, ob das Objekt, was du zurück bekommen hast auch wirklich ein Kontakt ist. :)
Delphi-Quellcode:
- edit -
const
// Folders olFolderContacts = 10; // Classes olContact = 40; olDistributionList = 69; procedure TForm1.Button1Click(Sender: TObject); var Outlook, NameSpace, Contacts, Contact: OleVariant; i, c: Integer; s, ItemClass: String; begin Outlook := CreateOleObject('Outlook.Application'); try NameSpace := outlook.GetNameSpace('MAPI'); try Contacts := NameSpace.GetDefaultFolder(olFolderContacts); try c := Contacts.Items.Count; for i := 1 to c do begin ItemClass := Contacts.Items[i].Class; if (StrToIntDef(ItemClass, -1) = olContact) then begin Contact := Contacts.Items[i]; s := Contact.Email1Address; // dein Code ******************************************************************* if (Length(s) = 0) then ShowMessage('Keine Adresse!'); //****************************************************************************** end; end; finally Contacts := Unassigned; end; finally NameSpace := Unassigned; end; finally Outlook := Unassigned; end; end; olDistributionList/69 ist eine Gruppe von Benutzern. |
Re: Outlook: Prüfen, ob Kontakt Mailadresse hat
Hallo Stefan,
danke für Deine Antwort. Ja, "contacts" hab ich gesetzt, aber das mit den Gruppen war mir neu, werds mal ausprobieren. Gruß Frank Nachtrag: Hat super funktioniert, danke! :thumb: |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:11 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz