加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Delphi – 从活动目录获取用户EmailAddress

发布时间:2020-12-15 09:12:34 所属栏目:大数据 来源:网络整理
导读:我试图通过使用Active Directory中的sAMAccountName来获取用户的电子邮件地址,但我收到此错误消息: The directory property cannot be found in the cache. 我可以获得全名,部门和自由裁量权,但为什么我收到电子邮件的错误? uses ActiveDs_TLB,adshlp;proc
我试图通过使用Active Directory中的sAMAccountName来获取用户的电子邮件地址,但我收到此错误消息:

The directory property cannot be found in the cache.

我可以获得全名,部门和自由裁量权,但为什么我收到电子邮件的错误?

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,rfIgnoreCase]);
    EdtMidName.Text := GetLastWord(xStrg);
    xStrg := StringReplace(RemoveDot,EdtMidName.Text,rfIgnoreCase]);
    xStrg := StringReplace(xStrg,rfIgnoreCase]);
    edtFirstName.Text := GetLastWord(xStrg);
    edtEmail.Text := Usr.EmailAddress;  // <<<<< this is the error 
  end;
end;

解决方法

使用WinNT://提供程序无法使用电子邮件地址属性,您需要使用LDAP://提供程序.该属性的名称是’mail’而不是’emailaddress’.这是ASDI和Delphi的链接. ASDI examples.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读