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

In reply to Win32::OLE is a possible by grinder
in thread Accessing MS Exchange by enoch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.