Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PERL MS Exchange address book (web based)

Posted on 2006-07-11
5
Medium Priority
?
511 Views
Last Modified: 2008-01-09
Hi everyone,

I am building an online application that would access the MS Exchange address book and display company contacts, aside many other things that this app does. I was wondering if anyone has done that in PERL and if PERL holds any libraries that help do that. If you can provide a code example it would be just amazing. I looked at the CPAN but I could not find anything there.

Thanks for you help.

L.
0
Comment
Question by:ledeni
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 17086372
You could try using LDAP:  http://search.cpan.org/~gbarr/perl-ldap-0.33/lib/Net/LDAP.pod
MS Exchange 5.0 is compatible with LDAP
0
 
LVL 25

Accepted Solution

by:
clockwatcher earned 1200 total points
ID: 17086915
Here's an example pulled from one of the scripts I use here at work to connect to our Exchange 5.5 box.  It uses ADO (basically an LDAP example but hidden underneath ADSI).  I went with it instead of straight LDAP because I had issues with the login.  If you have anonymous LDAP access enabled on your exchange server, normal LDAP shouldn't be a problem.  And the login problems may have just been me anyway.  If you're trying to query it from a non-windows box, this script won't work and normal LDAP will probably be your only option.

No matter which way you go a reference for the LDAP schema for Exchange 5.5 is here: http://www.microsoft.com/technet/prodtechnol/exchange/55/support/adsi.mspx

Ignore the commented section, I pull the SID account and do a SID to account name translation to get the windows account name for the mailbox-- chopped that section out because it doesn't pertain to your question.

Anyway, the following works for me:

use Win32::OLE;

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

my $query = '<GC://YOUREXCHANGESERVERNAME:389>;(objectClass=organizationalPerson);Assoc-NT-Account,Uid,ADsPath,cn,givenName,sn,mail,initials,telephoneNumber;subtree';

if ($conn) {

   $conn->{Provider} = "ADsDSOObject";
   $conn->Properties->{"User ID"} = "domainname\\username";
   $conn->Properties->{"Password"} = "userpassword";
   $conn->Properties->{"Encrypt Password"} = 1;

   $conn->Open("ADs Provider");
   my $rs = Win32::OLE->new('ADODB.Recordset');
   $rs->Open($query, $conn);
   if (! $rs->{EOF} ) {

     print "First Name^MI^Last Name^Alias^Emails^Phone #\n";

     my ($email, $nt, $cname, $uid, $fname, $lname, $phone);

     while (! $rs->{EOF} )
     {
      $email = $rs->fields("mail")->{Value};      
      $nt = $rs->fields("Assoc-NT-Account")->{Value};
      $cname = $rs->fields("cn")->{Value};
      $uid = $rs->fields("uid")->{Value};
      $fname = $rs->fields("givenName")->{Value};
      $lname = $rs->fields("sn")->{Value};
      $phone = $rs->fields("telephoneNumber")->{Value};
      $mi = $rs->fields("initials")->{Value};
                #  $sid = $rs->fields("Assoc-NT-Account")->{Value};
      #  $accountname = "";
      #  $accountName = GetNameFromSID($sid) if $sid =~ /^[A-F0-9]+$/ ;
      print "$fname^$mi^$lname^$uid^$email^$phone^$accountName\n" unless $accountName =~ /^zz/i;
      $rs->MoveNext();

     }
     
   }

   $rs->close;
   undef $rs;
   $conn->close;
   undef $conn;
}
0
 

Author Comment

by:ledeni
ID: 17087040
clockwatcher ... thanks a lot ... works like a charm !!

However, I noticed that this is using the win:32 library would this work if the website is deployed on the unix server ??? if not .. do you have any suggestions how it could be done.

Thanks .. credits well spent.

L.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17087191
No.  It won't work on a unix server.  If you're going to do this on unix, you'll need to use straight LDAP.   As I remember it, I had problems with authentication when I tried it that way though.  I'll see if I can put together a few minutes to try and get a working example using Net::LDAP.
0
 
LVL 25

Expert Comment

by:clockwatcher
ID: 17087794
Here's a Net::LDAP example that works for me.  If you don't have SSL enabled for your Exchange's LDAP, it'll transmit the password in clear text.  You might want to try an anonymous bind to see if you have any luck with it (I don't).

use Net::LDAP;

my $exchserver = "MyExchangeServer";
my $ntdomain = "NTDomainName";
my $ntaccount = "NTAccountName";
my $ntpass = "NTPassword";

my $organization = "EXCHANGE_ORGANIZATION";  # the o section of your X.400 address
my $site = "EXCHANGE_SITE";  # the ou section of your X.400 address

my $ldap = Net::LDAP->new("$exchserver");

my $mesg = $ldap->bind( "cn=$ntaccount,cn=$ntdomain", password => $ntpass) ;  #authenticated

# my $mesg = $ldap->bind() ; # anonymous -- this may work for you -- try it first -- doesn't for my set up

$mesg = $ldap->search(
                  base => "cn=Recipients,ou=$site,o=$organization",
                  filter => 'cn=*'
                  );

print "First Name^MI^Last Name^Alias^Emails^Phone #\n";

foreach $entry ($mesg->entries) {

  foreach ( qw(givenName initials sn uid mail telephoneNumber) )
  {
       print $entry->get_value($_)."^";
  }
  print "\n";

}

$mesg = $ldap->unbind;
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question