I had serious issues using Win32::OLE to access Outlook.  Memory usage was outrageous.  I found the CDO library to be much easier to use and much lighter on the resources.  It's been a while since I've dug into it, but I believe it has the ability to access any folder within Outlook, either based on an already existing Outlook instance, or by creating it's own.  You have to change the threading model in the registry (under MAPI.Session) to be "Apartment" I believe, otherwise the CDO library doesn't work correctly (although this may have been specific to the version I was using).
The code below is snippets from my script, it won't work as is.
Jeremy Blonde
#$Win32::OLE::Warn = 0;
my($SESSION) = Win32::OLE->new('MAPI.Session'); # Session Object
my($profile) = "$server\n"."$MAILBOX";
my($session, $profile) = @_;
# Logon using the specified $profile
print "Logging on...";
my $infostore = ${$session}->GetInfoStore();
if (!$infostore) {
  print "unsuccessful!\n";
print "  Scanning $infostore->{Name}\n";
# Get the RootFolder    
${$rootfolder} = $infostore->RootFolder();

# Get the folders collection
my($folders) = ${$parent}->Folders();  
# Get the first folder in the collection
my($folder) = $folders->GetFirst();   
while ($folder) {
  # Skip the Journal since it doesn't hold attachments
  if ($folder->{Name} eq "Journal") {
    $folder = $folders->GetNext();
my($folderName) = $folder->{Name};
# Recurse through any sub-folders
if ($folder->Folders->Count()) {
# Scan through the e-mail messages in the folder
if ($folder->Messages->Count()) {
  print "  Scanning: $folderName...\n";   
Jeremy Blonde
Network Technician
Davis Joint Unified School District
530.757.5300 ext. 117
-----Original Message-----
From: Ounsted, Toby [mailto:Toby.Ounsted@tl2k.co.uk]
Sent: Friday, October 17, 2003 7:19 AM
To: 'angelo.magnone@rbc.com'
Cc: Perl-Win32-Gui-Users (E-mail)
Subject: RE: [perl-win32-gui-users] Outlook - list all folders

Adapted from a similar script by Rob Hanson on perl-win32-users – hope this helps.


use strict;

use Win32::OLE;


# use existing instance if Outlook is already running, or launch a new 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 - Doe, John');




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);






sub listFolders {

            my $parent = shift;

            for (my $t = 1; $t <=$parent->Folders->Count;$t++){

            print $t . ": " . $parent->Folders->Item($t)->Name . "\n";




-----Original Message-----
From: angelo.magnone@rbc.com [mailto:angelo.magnone@rbc.com]
Sent: 17 October 2003 13:37
To: perl-win32-gui-users@lists.sourceforge.net
Subject: [perl-win32-gui-users] Outlook - list all folders



Does anyone have any examples of how to list all the folder names for a particular Outlook profile?
I'm looking at using Win32::OLE but can't figure out how to list ALL folder names.

Any help would be appreciated.

This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.

Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite. Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser immédiatement, par retour de courrier électronique ou par un autre moyen.