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

I have written several Perl scripts to make various modifications to MS Exchange. But, it really is a kludge. Basically, I use the commandline Exchange utilities to export a csv file, process the csv file (making the necessary changes), and then import it back into Exchange using the aforementioned commandline Exchange utilities. I hate doing it this way. So, I begin scouring the Internet for a Perl Exchange module.

I checked the usual spots to pick up Win32 modules (CPAN, ActiveState, Perl for Win32, Jenda's Perl module listing, Dada's Perl Lab,and of course, Dave Roth's page). But, I came up short. I could not find a module to directly access Exchange. So, I am turning to you, oh Theologicians of Perl. Does this exist?

In a nutshell, here is a quick example of the functionality I am looking for. Let's say there is a user whose mailbox display name in Exchange is "Schmoe, Jane". But, just last week, Jane got married to Joe Smith. She wants her mailbox name updated to reflect her new last name. Right now, this can be done via the Administrative Exchange GUI; or through the Perl script I wrote to export csv, modify, import csv. What I want is to directly access Exchange and change her name. *Poof* -- magic.

Has anyone heard of a module that can do this? Is there work being done to create such a module? Is Exchange so mind-numbingly bad that creating such a module is a "Abandon All Hope, Ye Who Enter Here" sorta deal?

Thank You,
Jeremy

Replies are listed 'Best First'.
Win32::OLE is a possible
by grinder (Bishop) on Feb 22, 2001 at 20:26 UTC

    I have grovelled about in Exchange with Win32::OLE, but it's not fun/easy. It really helps to have the VBA documentation for various magic numbers needed.

    I never had to do what you want to do, but I did, for instance, dump out all the messages in my folders, which is not possible from the Exchange client.

    I offer you the following code, hoping that you may find it a useful starting point.

    Disclaimer This may not necessarily be the best way of going about it. It got the job done and then I forgot about the code...

    0: #! /usr/perl/bin -w 1: 2: use strict; 3: use Win32::OLE qw/in/; 4: 5: use constant INBOX => 6; 6: 7: my $r; 8: eval { 9: $r = Win32::OLE->GetActiveObject('Outlook.Application') 10: }; 11: if ($@ || !defined($r)) { 12: $r = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;} +) or die "oops\n"; 13: } 14: 15: my $namespace = $r->GetNameSpace( 'MAPI' ) or die "can't open +MAPI namespace\n"; 16: 17: my $count = 0; 18: my $folder; 19: 20: if( $folder = $namespace->GetDefaultFolder( INBOX )) { 21: print "$folder->{Name}\n"; 22: my $f = $folder; 23: foreach( @ARGV ) { 24: mkdir $_, 0666; 25: chdir $_; 26: $f = $f->Folders( $_ ); 27: print "$f->{Name}\n" or die Win32::OLE->LastError() . "\n" +; 28: } 29: foreach my $it (reverse in $f->Items) { 30: ++$count; 31: print "$it->{ReceivedTime} $it->{Subject}\n"; 32: my $subj = $it->{Subject}; 33: $subj =~ tr/a-zA-Z0-9/_/c; 34: $subj =~ s/_+/_/g; 35: open OUT, sprintf( ">%03s-$subj.txt", $count ) or die "Can +not open $count for output: $!\n"; 36: print OUT <<EOM; 37: 38: To: $it->{To} 39: CC: $it->{CC} 40: From: $it->{SenderName} 41: Subject: $it->{Subject} 42: Date: $it->{ReceivedTime} 43: 44: $it->{Body} 45: EOM 46: close OUT; 47: } 48: } 49: else { 50: print "nop\n"; 51: }
Re: Accessing MS Exchange
by davemabe (Monk) on Feb 22, 2001 at 20:39 UTC
    You want to use Win32::OLE and ADSI. Another option is using Exchange's writable LDAP interface. I have found that ADSI works pretty well for what you want to do. Here is a your example in Perl:
    my $mailbox = Win32::OLE->GetObject("LDAP://EXCHSERVER/o=org/ou=orguni +t/cn=Recipients/cn=userDN"); $mailbox->{cn} = "Smith, Jane";

    or something like that. MSDN documents tells you how to get all the attribute identifiers. Note that for bulk imports, I have found that the command line utilities are much faster than any perl solution. Of course we do have over 100,000 recipients to update attributes for.

    Dave
      Don't you just hate when the solution is right under your nose, and you miss it. I never even considered using OLE and LDAP to get in there.

      You're a lifesaver, Dave.

      Thanks,
      Jeremy
Re: Accessing MS Exchange
by Jouke (Curate) on Feb 22, 2001 at 20:12 UTC
    I'm not into Exchange, but maybe I can point you to a certain direction.
    Is there something like a developers toolkit available with API specifications and C-headerfiles? If so, maybe you can write an XS-module or maybe even use Inline::C (read about it somewhere on Perlmonks yesterday)

    Hope it helps

    Jouke Visser, Perl 'Adept'