Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Win32::OLE is a possible

by grinder (Bishop)
on Feb 22, 2001 at 20:26 UTC ( #60234=note: print w/ replies, xml ) Need Help??


in reply to Accessing MS Exchange

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: }


Comment on Win32::OLE is a possible
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://60234]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2015-07-07 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls