Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Extracting email messages and attachments from a microsoft outlook .pst file

by wfsp (Abbot)
on Apr 08, 2011 at 13:49 UTC ( #898366=note: print w/ replies, xml ) Need Help??


in reply to Extracting email messages and attachments from a microsoft outlook .pst file

If Outlook is available you may be better off using that.

This is a skeleton of something I've used. You'd need to adjust the mailbox name.

#!/usr/bin/perl use v5.12.2; use warnings; use strict; use Win32::OLE; my $mail = parse_inbox(); sub parse_inbox{ # use existing instance if Outlook is already running, or launce a n +ew one my $ol; eval {$ol = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed" if $@; unless (defined $ol) { $ol = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit;}) or die "Oops, cannot start Outlook"; } my $mailbox = seekFolder( $ol->Session, 'Mailbox - John Sharpe' ); # adjust to suit my $folder = seekFolder( $mailbox, 'Inbox' ); my (%table); for (my $i = 1; $i <= $folder->Items->Count; $i++) { my $sender_name = $folder->Items->Item($i)->SenderName; my $subject = $folder->Items->Item($i)->Subject; my $body = $folder->Items->Item($i)->Body; say $subject; # process # store something in table } return \%table; } sub seekFolder { my $obj = shift; my $target = shift; for (my $i = 1; $i <= $obj->Folders->Count; $i++) { if ($obj->Folders->Item($i)->Name eq $target) { return $obj->Folders->Item($i); } } return; }
Tested with Outlook 2003. There is a snag in that after the script is started Outlook complains that something is trying to look at the contact list. You need to click a checkbox and OK.


Comment on Re: Extracting email messages and attachments from a microsoft outlook .pst file
Download Code
Re^2: Extracting email messages and attachments from a microsoft outlook .pst file
by pankaj_it09 (Scribe) on Apr 20, 2011 at 12:24 UTC
    Is perl version 5.12.2 required ?

    I commented the perl version line and then ran the code which showed the below error:

    Can't call method "Folders" on an undefined value at outlook.pl line 57.
      Have you got the correct mailbox name? It should be exactly as Outlook displays it. You could add a debug print statement in the seekFolder subs for loop to see which folders are found. Something like
      print "Folder:", $obj->Folders->Item($i)->Name;
      You don't need 5.12.2, when I first used it I was on 5.8.8.
        Actually the input is a *.pst file so the mailbox name is unknown.
        What to do ?
Re^2: Extracting email messages and attachments from a microsoft outlook .pst file
by pankaj_it09 (Scribe) on Apr 29, 2011 at 13:02 UTC
    The code runs in Outlook 2007 but the count it calculates is 0 even though the "Inbox" has a large amount of messages.

    Hence the below loop is not executed :

    for (my $i = 1; $i <= $folder->Items->Count; $i++) {

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2014-09-21 00:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls