Delphi - get user EmailAddress from active directory

I am trying to get the email address of a user using sAMAccountNamefrom Active Directory, but I am getting this error message:

The catalog property could not be found in the cache.

I can get the full name, department and discretion, but why am I getting this error for email?

uses
  ActiveDs_TLB, adshlp;

procedure TMainForm.btnFillInfoClick(Sender: TObject);
var
  Usr: IAdsUser;
  lStr: HRESULT;
  xStrg: string;
  ChkPRN: string;
  RemoveDot: string;
begin
  //connect to AD and try exrtact the info /
  lStr := ADsGetObject('WinNT://10.120.200.16/'+edtPRN.Text, IADsUser, usr); // edtPRN.Text >> sAMAccountName
  if Succeeded(lStr) then
  begin
    Usr.GetInfo;
    EmpFullName := Usr.FullName;
    RemoveDot := StringReplace(EmpFullName, '.', '',[rfReplaceAll, rfIgnoreCase]);
    xStrg := Usr.FullName;
    edtLastName.Text := GetLastWord(xStrg);
    xStrg := StringReplace(RemoveDot, edtLastName.Text, '',[rfReplaceAll, rfIgnoreCase]);
    EdtMidName.Text := GetLastWord(xStrg);
    xStrg := StringReplace(RemoveDot, EdtMidName.Text, '',[rfReplaceAll, rfIgnoreCase]);
    xStrg := StringReplace(xStrg, edtLastName.Text, '',[rfReplaceAll, rfIgnoreCase]);
    edtFirstName.Text := GetLastWord(xStrg);
    edtEmail.Text := Usr.EmailAddress;  // <<<<< this is the error 
  end;
end;
+4
source share
1 answer

The email address attribute is not available using the WinNT: // provider, you need to use the LDAP: // provider. The attribute name "mail" is not "emailaddress". Here is a link to ASDI and Delphi. Examples ASDI .

+1

Source: https://habr.com/ru/post/1535148/


All Articles