Retrieving e-mail and user details.

Hello all,
I'm developing an application for a corprate Intranet where everybody is using NT & they're also using MS Exchange with outlook.

This form needs the users name and email address, is it possible to pull there name & smtp email address from the client/user machine? The reason I say smtp is that with outlook you only see the reciepents name when you send an email so a lot of the employees don't even know there full email address.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What version of exchange?  If it's 5.5, you should be able to use ADO with LDAP to pull the user's email.

I've got some sample code around here that I wrote a long while back, if I can find it again, I'll post it.  If not, here's a link that could help you get started.
rupertsAuthor Commented:
Also seeing that document I can get their name as well!

I'm looking to the version of exchange as the server is elsewhere!
rupertsAuthor Commented:
mmm english gone to pot..

Try again.

I also saw that you can get the user name as well
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

rupertsAuthor Commented:
mmm english gone to pot..

Try again.

I also saw that you can get the user name as well
rupertsAuthor Commented:
Right note to self, don't press refesh after submitting a comment!

Anyway, yes we are using Exchange 5.5, and if you have any code that would be excellent!

Basically when the user loads this form, there name & email will appear at the top so that they know that we know who they are!
Maybe I'm missing something here...

But I don't see how you can access client side exchange information from asp (processed on the server).

Is this possible?

Aren't you pretty much limited on client information to whatever is sent through the http header?

When we want to ID somebody, we usually use IP address or something like that.
rupertsAuthor Commented:

This is to be installed on a intranet, all users must first log in to NT to access the intranet, because of this each user has an id which can used to find out their details (somehow!)

Hmmm.... unless their login is the same as there Exchange login I don't know if you can pop someones email address.  Unless you populate a dB with the users information first, then pull this in to the page.
rupertsAuthor Commented:
... unless their login is the same as there Exchange login

I'm no NT expert, but I'm 99% sure they must be the same otherwise they would have to log on to the mail separatly, which as far as I know they don't.
Right, it is common to have different logins for the intranet and email, as far as I have experienced.
Assuming the login names are the same this should work-- works for me, anyway.  It assumes you're using an Authenticated entry (set NTFS rights on the script so that the IUSR_MachineName account has "No Access" rights and set up IIS to allow Windows NT Challenge/Response on the script file).  On an intranet with clients running IE, you shouldn't get a login prompt (unless they've changed the default Intranet security settings).  If they're running Netscape, you'll have to allow clear text passwords and they'll be forced to deal with a login prompt.  If that's a problem, you can figure out who's logged in just based on IP-- without any authentication scheme (therefore, no prompts in either IE or NS)-- but I won't go into how to do that here.


  username = request.servervariables("AUTH_USER")
  domainseparator = instr(1, username, "\")
  if domainseparator > 1 then username = mid(username, domainseparator + 1)
  criteria = "uid=" & username

  'Replace EXCHANGESERVER below with the name of your Exchange server
  query = "<LDAP://EXCHANGESERVER>;(" & criteria & "); rdn, cn, mail, uid"

  set conn = server.createobject("ADODB.Connection")
  conn.Provider = "ADsDSOObject"
  conn.Open "Exchange Server"
  set rs = server.createobject("ADODB.Recordset") query, conn
  if not rs.eof then
     response.write "Display Name: " & rs("cn") & "<BR>"
     response.write "Email: " & rs("mail") & "<BR>"
     response.write "Alias: " & rs("uid") & "<BR>"
     response.write "Relative Distinguishing Name: " & rs("rdn") & "<BR>"
     response.write "Can't find " & username & " in Exchange Directory<BR>"
  end if

  set rs = nothing

  set conn = nothing



If as mgfranz mentions, your Exchange alias differs from your NT account name, then the following Perl program should still work for you.  It retrieves the SID for the username and queries exchange for the account with the matching SID.  It's written in Perl because it requires an API call-- it would be simple to rewrite as an ActiveX DLL in VB, if you wanted.

use Win32::OLE;
use Win32::API;
use CGI::Carp ('fatalsToBrowser');

$username = $ENV{"AUTH_USER"};
print "Content-Type: text/html\n\n";

$SID = " " x 1024;
$SIDBufSize = length $SID;
$domainName = " " x 128;
$domainLength = length $domainName;
$SIDType = " " x 2048;
# replace DOMAINCONTROLLER with the name of a PDC or BDC
$computer = "\\\\DOMAINCONTROLLER";

$GetSID = new Win32::API("advapi32", "LookupAccountName", [P, P, P, P, P, P, P], N);
$GetLastError = new Win32::API("kernel32", "GetLastError", [], N);

$myVal = $GetSID->Call($computer, $username, $SID, $SIDBufSize, $domainName, $domainLength, $SIDType);
if ($myVal == 0) {
  print "Error Retrieving SID-- Error Number: ".$GetLastError->Call()."\n"; }
else {
 $SID =~ s/ {1,}$//;
 @myBits = unpack("C*",$SID);
 foreach (@myBits) { $mySID.= uc sprintf("%2.2x",$_); }
 print "SID: $mySID<BR>\n";

$conn = Win32::OLE->new('ADODB.Connection');

$criteria = "Assoc-NT-Account=$mySID";

$query = '<LDAP://EXCHANGESERVERNAME>;('.$criteria.'); rdn, Assoc-NT-Account, cn, mail, uid, name';

if ($conn) {
   $conn->{Provider} = "ADsDSOObject";
   $conn->Open("Exchange Server");
   $rs = Win32::OLE->new('ADODB.Recordset');
   $rs->Open($query, $conn);
   if (! $rs->{EOF} ) {
     $email = $rs->fields("mail")->{Value};
     $nt = $rs->fields("Assoc-NT-Account")->{Value};
     $cname = $rs->fields("cn")->{Value};
     $rdn = $rs->fields("rdn")->{Value};
     $uid = $rs->fields("uid")->{Value};
   else {
     $email = "Can't find $username in Exchange Directory";
   undef $rs;
   undef $conn;

print "Logged in user is: $username<BR>\n";
print "Domain is: $domainName<BR>\n";
print "Alias is: $uid<BR>\n";
print "Email Address is: $email<BR>\n";
print "NT Account is: $nt<BR>\n";
print "Account Display Name: $cname<BR>\n";
print "RDN is: $rdn<BR>\n";


Anyway, hope it helps.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rupertsAuthor Commented:
Right I'll have to get back to you on Monday, when I'm let loose on the server!

Nice Perl code Clockwatcher... :-)

rupertsAuthor Commented:
Its all gone wrong :-(

Not your code, but our set up, I've now been told that we have different user names for NT and for Exchange (so no e-mail look up) secondly security between the Intranet Server and the Users is such that they have to logon on again when using NT Chall/Resp, which I'm doing so I know who they are!

But anyway I'm sure you code would have worked perfectly.. So have a A+!

Look at downloads here-------->
rupertsAuthor Commented:
thanks, but I now move on from that project - actually I've changed jobs!!
Per recommendation, force-accepted by
CS Moderator
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.