[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 234
  • Last Modified:

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.

Rupert
0
ruperts
Asked:
ruperts
  • 9
  • 3
  • 2
  • +3
1 Solution
 
clockwatcherCommented:
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.

http://msdn.microsoft.com/library/backgrnd/html/msdn_adsiexch.htm
0
 
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!
0
 
rupertsAuthor Commented:
mmm english gone to pot..

Try again.

I also saw that you can get the user name as well
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
rupertsAuthor Commented:
mmm english gone to pot..

Try again.

I also saw that you can get the user name as well
0
 
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!
0
 
mayhewCommented:
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.
0
 
rupertsAuthor Commented:
Mayhew,

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!)

Rupert
0
 
mgfranzCommented:
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.
0
 
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.
0
 
mgfranzCommented:
Right, it is common to have different logins for the intranet and email, as far as I have experienced.
0
 
clockwatcherCommented:
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")
  rs.open 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>"
  else
     response.write "Can't find " & username & " in Exchange Directory<BR>"
  end if

  rs.close
  set rs = nothing

  conn.close
  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";
   }
   $rs->close;
   undef $rs;
   $conn->close;
   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.
0
 
rupertsAuthor Commented:
Right I'll have to get back to you on Monday, when I'm let loose on the server!

Rupert
0
 
mgfranzCommented:
Nice Perl code Clockwatcher... :-)

Mark
0
 
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+!
0
 
grizzle053098Commented:

Look at downloads here-------->
http://www.cdolive.com/
0
 
rupertsAuthor Commented:
thanks, but I now move on from that project - actually I've changed jobs!!
0
 
NetminderCommented:
Per recommendation, force-accepted by
Netminder
CS Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 9
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now