qadwjoh has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I'm trying to access our company Exchange address book from a Perl script. I've had a look through the archives here and on other sites, but can't find any understandable explanation on how to do it - I have no knowledge of how Exchange works.

I just want to connect to an Exchange server, open the address book, look up a user name (or alias would be better) and get the department that user belongs to. And I need to do this from a Windows (2000) machine running ActivePerl.

Any ideas anyone?
A
  • Comment on Accessing Exchange Address Book from Perl

Replies are listed 'Best First'.
Re: Accessing Exchange Address Book from Perl
by strat (Canon) on Oct 15, 2003 at 15:31 UTC
Re: Accessing Exchange Address Book from Perl
by jacques (Priest) on Oct 15, 2003 at 16:20 UTC
    I have Exchange experience with Perl. You need to look at the msdn library. Also there are some helpful nodes here. Just do a super search for Exchange. I know it can be frustrating to figure it out since most of the examples you will see involve VB, but with a little experimentation, you should accomplish your goal.
Re: Accessing Exchange Address Book from Perl
by ChrisR (Hermit) on Oct 15, 2003 at 19:19 UTC
    I have been working with exchange and perl for a couple of years now and I've learned at least one thing: It ain't easy!! But I'm sure you will find that out for yourself if you haven't already. Now that I've gotten that out of the way, try this on for an example:
    #!c:\perl\bin\perl.exe -w use strict; use warnings; use diagnostics; use Net::LDAP; #The following will be different depending on your mail server my $mailserver = "mail.company.com"; #internet accessible name of the +server my $port = 389; #LDAP port number my $org = "organization"; #Top level Exchange Organization (o) my $site = "site"; #Actual exchange site my $ldap = Net::LDAP->new($mailserver,port=>$port) or die "$@"; my @Attrs = (); # request all available attributes to be returned. my $result = $ldap->search ( base => "cn=Recipients,ou=$site,o=$org", scope => "sub", filter => "cn=*", attrs => \@Attrs ); my @entries = $result->entries; foreach my $entr ( @entries ) { print "DisplayName: ",$entr->get_value('cn'),"\n"; print "Department: ",$entr->get_value('department'),"\n"; print "Email: ",$entr->get_value('mail'),"\n"; print "#-------------------------------\n"; } $ldap->unbind(); exit;
    Update:
    I got this to work on both win2K and linux.
      Thanks Chris,

      got your code to work, but had to install Net::LDAP and all it's required modules by hand...

      Just a couple of questions though - I'm specifically looking for one user, based on their email address |(or full name) and I only need to know their department details. Do I have to load all information about all employees - it's a pretty big company and I'm worried about memory and performance issues. Is it possible to request information on just one person?

      thanks,
      A

      UPDATE:
      Got this to work by changing the base to just "o=$org", and changing the filter to "(&(cn=*) (uid=$uid))". I also added "$entr->dump" to get all the values stored.