#!/usr/bin/perl -w # Check an exchange 5.5 server to see if an address exists # Exchange 2k uses # proxyAddresses: smtp: # proxyAddresses: SMTP: # instead of otherMailbox use strict; use Net::LDAP; my $ServerName = "my.ldap.server"; my $searchBase = "cn=Recipients,ou=SITE,o=\"My Organization\""; my $recipient = $ARGV[0]; my $ldap = Net::LDAP->new("$ServerName"); unless($ldap) { die "$0: Could not connect to $ServerName"; } #if you can connect, then bind my $mesg = $ldap->bind(version => 3) or die $@; # don't use die in mimedefang; $recipient =~ tr/<>//d; # strip angle brackets $mesg = $ldap->search ( base => "$searchBase", filter => "| (mail=$recipient)(proxyAddresses=smtp:$recipient)", attrs => "['mail','proxyAddresses']" ) or die "$@"; my $count = $mesg->count; # number of LDAP entries that matched # print "Recieved $count entries for $recipient\n"; if ($count == 0) { # invalid recipient print "Invalid recipient\n"; # return('REJECT', "Invalid recipient") } else { foreach my $entry ( $mesg->entries ) { if ($entry->get_value( "mail" ) =~ /$recipient/i) { # matched primary addy print $recipient." OK\n"; } else { # matched otherMailbox foreach my $mail ( $entry->get_value( "otherMailbox" ) ) { if ( $mail =~ s/^(smtp|SMTP)\$($recipient)$/$2/igs) { print $mail." OK\n"; } } } # return ('CONTINUE', "ok"); } } # Unbinding $ldap->unbind;