Einzelnen Beitrag anzeigen

Benutzerbild von ste_ett
ste_ett

Registriert seit: 10. Sep 2004
Ort: Dülmen
464 Beiträge
 
Delphi 7 Professional
 
#2

Re: Outlook: Prüfen, ob Kontakt Mailadresse hat

  Alt 22. Feb 2007, 15:28
In deinem Code taucht auf einmal "Contact" auf.

Hast du das gesetzt?

Contact := Contacts.Items[i]; Der zweite Punkte ist, dass Outlook dir in dem Array der Kontakte nicht nur einzelne Kontakte, sondern auch Gruppen von Kontakten zurückgibt.
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:
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;
- edit -

olDistributionList/69 ist eine Gruppe von Benutzern.
Stefan
"Geht nicht!" ist keine Fehlerbeschreibung und "Hab ich schon versucht!" keine Antwort!

Hey, it compiles! Ship it!
  Mit Zitat antworten Zitat