Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Mail::Outlook and Archive.pst

by McA (Priest)
on Mar 22, 2013 at 14:48 UTC ( #1024934=note: print w/replies, xml ) Need Help??

in reply to Mail::Outlook and Archive.pst


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

Replies are listed 'Best First'.
Re^2: Mail::Outlook and Archive.pst
by VMat (Novice) on Mar 22, 2013 at 19:32 UTC
    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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1024934]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2018-05-22 14:07 GMT
Find Nodes?
    Voting Booth?