Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Mail::Outlook and Archive.pst

by VMat (Novice)
on Mar 22, 2013 at 12:45 UTC ( #1024922=perlquestion: print w/replies, xml ) Need Help??
VMat has asked for the wisdom of the Perl Monks concerning the following question:


I'm trying to read messages from a pst in Outlook using Mail::Outlook but I can't seem to find a way to reach the right folder. If I remember well, it used to work on Outlook 2003 - now I have Outlook 2010 here, do you know if that makes any difference?

This is what I did:

use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; use Mail::Outlook; my $outlook1 = new Mail::Outlook(); my $folder1 = $outlook1->folder('Archive/Inbox'); die "Can't open mailbox\n" unless ($folder1);

And it always dies. Outlook is open, "Archive" is open, and it does have an "Inbox". I already checked and $outlook1 is not empty - I can print its keys, for example.

As I said, I believe I used the same code a few years ago to read messages from Outlook 2003.

Please help...

Thank you,


Replies are listed 'Best First'.
Re: Mail::Outlook and Archive.pst
by McA (Priest) on Mar 22, 2013 at 14:48 UTC


    I suppressed doing such things as OLE automation. IMHO it was ugly and it will be.

    Anyway I was curious as I do have Outlook 2010 here on my Win-Box. So, what were my steps:

    1. Download Strawberry Perl (of course newest version, 64bit, I'm brave)

    2. Install it. (This is what always have been nice with Windows: Install.exe->Next->Next->Yes->Next->Next->Complete)

    3. Download cpan-Fatpacker by hand from and store it to

    4. Execute perl App::cpanminus. Haha, all went well cpanm is installed. I really like it. Thank you, Tatsuhiko Miyagawa!

    5. So, the next building block: Execute cpanm -v local::lib, some seconds and many lines of output later, also installed. Very nice. Whom have I thank for that? Metacpan is listing someone different than CPAN. Mmmhh, probably worth another Monk's thread.

    6. Create a directory in c:\Temp\something and change to that.

    7. Now let's install Mail::Outlook with a simple cpanm -v -l lib Mail::Outlook. Argggh, the installation of the prerequesites went well, installation of Mail::Outlook canceled by test error. Ok, let's have a look into the test. Aha, it seems that exactly the piece of code dies which doesn't work for VMat asking for wisdom.

    8. Ok, being brave and knowing that I won't mess up my perl installation using a seperate install directory with the help of cpanm I use a forced install: cpanm -v -l lib --force Mail::Outlook.

    9. So, now knowing that this whole OLE dynamic typing and naming stuff is made by evil I make the qualified guess that something is wrong with the usage of the name 'Inbox'.

    10. Let's dig around the documentation of Win32::OLE::Const. And what do I find in the synopsis? A nice example iterating over OLE constants. So let's use it for our Outlook example.

      my $wd = Win32::OLE::Const->Load("Microsoft Outlook"); foreach my $key (keys %$wd) { printf "$key = %s\n", $wd->{$key}; }
      And what do I find after sorting and searching: olFolderInbox.

    11. So, I take this piece of information and build the following script:

      use strict; use warnings; use local::lib './lib'; use Data::Dumper; use Mail::Outlook; use Win32::OLE::Const 'Microsoft Outlook'; my $outlook = Mail::Outlook->new(); my $folder = $outlook->folder(olFolderInbox); my $message = $folder->first(); my $accessor = "SenderName"; my %mail = map { $_ => $message->$_ } qw( SenderName To Cc Bcc Subject + Body); print Dumper(\%mail), "\n";

    12. Now, fingers crossed, gleeful anticipation: perl! I see the output of the first mail in my inbox which is called "Posteingang" in my Outlook by the way.

    13. Last step to do: Give an answer on PerlMonks hoping it will make VMat's weekend happier. You have to excuse the whole story, but I thought that it may be helpful for others to see, how easy you can try some perl modules even under Windows without messing up your main installation. So this story is not only the presentation of a solution to the initial request, but also a little recipe for trying things without hassle.

    Happy weekend

      Boy... there's a lot of stuff in there for me to learn. Thanks a lot!

      However... I don't see where you set which Inbox you're pointing $outlook to. I guess you've reached your main Inbox - I'm trying to read messages from my Archive (which used to be 'Archive/Inbox', but that name doesn't work anymore).

      Do you know how we could access the Archive mailbox?




        It's been a while and I don't work for that firm now, so these are the steps to take not code.

        Start up Outlook and select the folder.

        In your code using $ol as the OLE connection to Outlook -

        Use '$exp = $ol->ActiveExplorer to find the right instance of Outlook.

        $sel = $exp->Selection to get the selected folder details.

        These should include the folder's name.

        Like I say this is from memory, so may need some ( a lot ) of work, but should point you in a viable direction.


Re: Mail::Outlook and Archive.pst
by hdb (Monsignor) on Mar 22, 2013 at 13:06 UTC

    I do not have Outlook, but if the module Mail::Outlook is based on Win32::OLE , you can

    print Win32::OLE->LastError();

    to see what the last error was, if any.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1024922]
Approved by johngg
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-02-20 06:39 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (267 votes). Check out past polls.