cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
It works fine for the most part, but when there is an empty field in the message object I get an OLE error like:#!/usr/bin/perl -w use strict; use Win32::OLE; $| = 1; # use existing instance if Outlook is already running, or launce 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, 'foo@bar.com'); my $folder = seekFolder($mailbox, 'Inbox'); my @fields = qw(SenderName SenderEmailAddress ReplyRecipientName +s SenderEmailType SentOn ReceivedTime MessageClass Siz +e Subject To CC BCC Unread InternetCodepage Impo +rtance EntryID ConversationIndex ConversationTopic Class + BodyFormat ); my $end = $folder->Items->Count; for (my $i = $end; $i > $end-5; $i--) { print "=========================================================== +===========\n"; foreach my $k (@fields) { print "$k: ".$folder->Items->Item($i)->{$k} . "\n"; } } Win32::OLE->FreeUnusedLibraries(); 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); } } }
I tried to avoid this by enclosing the print statement in an if defined clause, but this does not change anything. Anyone know how to avoid this error?Win32::OLE(0.1709) error 0x8002000e: "Invalid number of parameters" in METHOD/PROPERTYGET "InternetCodepage" at C:\recover\boxcutter\n +ewtry\test.pl line 27. Use of uninitialized value in concatenation (.) or string at C:\recove +r\boxcutter\newtry\test.pl line 27.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32::OLE Outlook Error
by Anonymous Monk on Oct 09, 2014 at 06:57 UTC | |
by cormanaz (Deacon) on Oct 09, 2014 at 13:25 UTC |