In the past we have done this with Lotus Notes (many years ago), but the
email system moved to Outlook and MS Exchange. The client is not sure when
the code below started failed, but they would like to change the code to
access the MS Exchange list.
------------------------
// retrieve addresses from ldap
function GetAddressBook()
{
var conn;
var cmd;
var rs;
var cnt;
var sCompare, sSearch, sCommand;
addrBook = new Array();
addrBookMail = new Array();
// if search is given, add it to ldap search as start of displayName
sSearch = window.opener.TO.AddrSrch.value;
if( sSearch != "" )
sCompare = "(displayName=" + sSearch + "*)";
else
sCompare = "";
conn = new ActiveXObject("ADODB.Connection");
conn.Provider = "ADsDSOObject"; // this is the ADSI-OLEDB provider name
// Set username and password
conn.Properties("User ID") = "CN=ldap,CN=Users,DC=**,DC=****,DC=**,DC=***";
conn.Properties("Password") = "password";
// Open Connection
conn.Open( "Active Directory Provider" );
rs = new ActiveXObject("ADODB.Recordset");
// insert displayName comparison into command
sCommand = "<GC://ipaddress>;(&(mailnickname=*)(l=********)" + sCompare +
");mail,displayName;subtree";
rs.Open( sCommand, conn);
cnt = 0;
while( !rs.EOF )
{
addrBook[cnt] = rs.Fields("displayName").value;
addrBookMail[cnt] = rs.Fields("mail").value;
cnt++;
rs.MoveNext();
}
return cnt;
}
------------------------
Does anyone have some sample code displayng this type of functionality so I
can be led in the correct direction?
I have found the following url which looks like an LDAP search using what
looks like a sql SELCT statement.
http://www.washington.edu/computing/eds/whitepages/jsexample.html
I found this url, but it looks like C#.
http://weblogs.asp.net/whaggard/archive/2007/01/30/how-do-i-access-my-outlook-contacts-from-my-web-application.aspx
Can you describe more about how did you play around iwth the "User ID and
"Password"? I am also ecounter similar problem.
Thanks.
I changed the following lines from the code I posted and it started to work:
conn.Properties("User ID") = "CN=Administrator,CN=Users,DC=******,DC=***";
conn.Properties("Password") = "*****";
sCommand = "<GC://0.0.0.0>;(&(mailnickname=*)" + sCompare +
");mail,displayName;subtree";
The "User ID" has to be an Active Directory user. If you do not have access
to Active Directory, you can try running something like Softerra LDAP
Browser. Browse to your user (I went to the CN=Users folder) and take a look
at the distinguishedName attribute. That is what I put into the "User ID"
line shown above.
The "Password" is obviously the user's password.
As for the sCommand line, change 0.0.0.0 to the ip address of your Active
Directory server.
Thanks,
Bill