Greetings Bros. I am working on some Outlook automation and have started out by just trying to print the contents of some message fields like so:
#!/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); } } }
It works fine for the most part, but when there is an empty field in the message object I get an OLE error like:
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.
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?

In reply to Win32::OLE Outlook Error by cormanaz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.