At first, I'm not sure if you can access messages on Exchange with LDAP because I've never tried. I always did so via CDO (=Win32::OLE). All I've already done with Exchange and LDAP is creating distribution lists.
I prefer using the module-group Net::LDAP (called perl-ldap on CPAN or Activestate).
You can connect to Exchange like to any other LDAP-Server about in the following way:
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_text ldap_error_name);
# adapt the following variables to your exchange-Server
my $server = "192.168.0.1"; # or hostname
my $port = 389;
my $user = "cn=username,cn=Recipients,ou=Location,o=Company";
my $password = "topSecret";
my $version = 3;
# connect to server
my $c = Net::LDAP->new($server, port=>$port);
die "Error: couldn't connect: $@\n" unless ($c){
# try to bind as user
my $mesg = $c->bind( $user, password => $password,
version => $version);
if ($mesg->code()){ # on error
# get errormessages
my $errorCode = $mesg->code;
my $errorText = ldap_error_text($mesg->code);
my $errorMsg = ldap_error_name($mesg->code);
$c->Disconnect();
die <<EOD;
Error in bind:
Code: $errorCode
Message: $errorMsg
Text: $errorText
EOD
;
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print" |