Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am having some troubles with the Outlook OLE and accessing some of its methods from Perl. Specifically, I'm looking to get the attachments from a file sitting in a public mailbox and move them to the network. A paired down version of my code is below:

use strict; use warnings; use Win32::OLE; use Win32::OLE::Const '.*Outlook'; my $outlook = Win32::OLE->GetActiveObject('Outlook.Application'); die "Outlook isn't running." unless $outlook; my $namespace = $outlook->GetNameSpace("MAPI"); # some code here to get the location of the mailbox and the inbox of t +hat mailbox my $inbox = $namespace->Folders($i)->Folders($j); # some code here to get to the proper email message my $text = $inbox->Items->Item($wanted);

Now from here I know I have the right message because print $text->Subject; will return the subject line. The problem is I can't seem to get anything else. I've looked through the object browser in outlook and I've tried Attachments but it doesn't seem to work. For instance, print $text->Attachments->Count; just returns the warning "Can't call method "Count" on an undefined value." Also, body/to/from etc. don't seem to return anything either. Does anyone have any tips/ideas? I checked the class of the item and it is class 43 (mailitem.)

Replies are listed 'Best First'.
Re: Accessing Outlook OLE with Perl
by wfsp (Abbot) on Mar 15, 2011 at 17:49 UTC