I used Redemption together with Win32::OLE module with strawberry perl to parse emails out of a pst file and save attachements and body to disk.

Here is some rough code to do this

#!perl use strict; use Win32::OLE; use Win32::OLE::Const; use Win32::OLE::Const 'Microsoft Outlook'; use Data::Dumper; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use IO::File; use Win32::OLE::Variant; my $outlook; eval { $outlook = Win32::OLE->GetActiveObject('Outlook.Applic +ation') }; if ($@ || !defined($outlook)) { $outlook = Win32::OLE->new('Outlook.Application', sub +{$_[0]->Quit;}) or die("Cannot create outlook\n"); } my $namespace = $outlook->GetNamespace('MAPI'); # get the proper pst file my $folder = $namespace->{'Folders'}{'somepst'}; # now get the folder within the pst file my $folder2 = $folder->{'Folders'}{"dailyfolder"}; # get all the messages my $msgs = $folder2->{Items}; my $ncon = $msgs->{Count}; print "number of contacts - $ncon\n\n"; # this works my $app = new Win32::OLE('Redemption.SafeMailItem'); my $con; my $at; my $fn; my $obase = 'C:\strawberry\perl\daily\\'; my $out; my $po = {}; foreach my $ii (1 .. $ncon) { $con = $msgs->Item($ii); $app->{'Item'} = $con; #print_body($app->{Body}); #find_data($app->{Body},$ii,$t); $at = $app->{'Attachments'}; print "\n\n Attachment count\n"; print $at->{Count} . "\n"; $fn = $at->Item(1)->{FileName}; print "filename is $fn\n" if $fn; $out = $obase . $fn; if(!-e $out) { $at->Item(1)->SaveAsFile($out); print "SAVING ATTACHMENT TO $out\n"; } $po->{$out}++; } my $z = Archive::Zip->new(); my $i = 1; my $fh; my $fl; my $exf = {}; my $he = 0; foreach my $zf (keys %$po) { warn("processing $zf\n"); unless( $z->read($zf) == AZ_OK) { die("ERROR READING $zf\n"); } foreach my $m ($z->memberNames()) { warn("processing member $m\n"); if(! -e "$obase$m") { $fh = IO::File->new("$obase$m",">") or + die($!); $fl = $z->memberNamed($m); $fl->extractToFileHandle($fh); $fh->close() if $fh; if($m =~ /\.xls$/) { $exf->{"$obase$m"}++; $he++; } next; } } }


In reply to Re: is it possible to use Perl to process Outlook emails? by tmaly
in thread is it possible to use Perl to process Outlook emails? by mertserger

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.