Discussion:
Client Side JavaScript Email Search/Lookup in MS Exchange
(too old to reply)
Bill Anagnostos
2009-05-04 13:56:08 UTC
Permalink
I have been assigned to a task to create an email search/lookup tool that
will allow a user to type a few characters of a person's name and retrieve a
list of email addresses from MS Exchange. The preferred language is
JavaScript since the rest of the app is predominantly JavaScript.

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
Bill Anagnostos
2009-05-08 14:48:01 UTC
Permalink
After searching around, playing with settings, etc, the code I posted is
working. This code is actually looking up displayName (person's name) and
mail (email address) from an LDAP server (AD in my case). I had to play
around with the "User ID", "Password", and the sCommand. That got it to work.
Post by Bill Anagnostos
I have been assigned to a task to create an email search/lookup tool that
will allow a user to type a few characters of a person's name and retrieve a
list of email addresses from MS Exchange. The preferred language is
JavaScript since the rest of the app is predominantly JavaScript.
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
Ernest
2009-06-02 10:25:02 UTC
Permalink
Hi Bill,

Can you describe more about how did you play around iwth the "User ID and
"Password"? I am also ecounter similar problem.

Thanks.
Post by Bill Anagnostos
After searching around, playing with settings, etc, the code I posted is
working. This code is actually looking up displayName (person's name) and
mail (email address) from an LDAP server (AD in my case). I had to play
around with the "User ID", "Password", and the sCommand. That got it to work.
Post by Bill Anagnostos
I have been assigned to a task to create an email search/lookup tool that
will allow a user to type a few characters of a person's name and retrieve a
list of email addresses from MS Exchange. The preferred language is
JavaScript since the rest of the app is predominantly JavaScript.
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
Bill Anagnostos
2009-06-02 13:43:01 UTC
Permalink
Ernest,

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
Post by Ernest
Hi Bill,
Can you describe more about how did you play around iwth the "User ID and
"Password"? I am also ecounter similar problem.
Thanks.
Post by Bill Anagnostos
After searching around, playing with settings, etc, the code I posted is
working. This code is actually looking up displayName (person's name) and
mail (email address) from an LDAP server (AD in my case). I had to play
around with the "User ID", "Password", and the sCommand. That got it to work.
Post by Bill Anagnostos
I have been assigned to a task to create an email search/lookup tool that
will allow a user to type a few characters of a person's name and retrieve a
list of email addresses from MS Exchange. The preferred language is
JavaScript since the rest of the app is predominantly JavaScript.
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
Loading...