I am attempting desperately (and failing) to use Win32::OLE to manipulate emails in Outlook 2007.
The code below is a fairly stripped down version... note that I have no problem marking an email Read or Unread, however setting other properties, and calling some methods, doesn't work. :(
The most frustrating part is that once in awhile, it DOES work for 1 email, but not any of the others! And I can't reliably reproduce the success.
In desperation, you'll note in the code that I tried looping through a single email infinitely until it set the Category correctly... but that doesn't work either :(
Please show me the error(s) of my ways!
Thanks for any response, even if it is just to call me stupid!
use strict;
use warnings;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Outlook';
$|++;
#get an Outlook object
my $outlook;
$outlook = Win32::OLE->new('Outlook.Application');
die unless $outlook;
#get the Inbox folder
my $namespace = $outlook->GetNamespace("MAPI");
my $folder = $namespace->Folders("My Folder");
my $n = $folder->Items->Count;
my $i=0;
my $from;
for ($i=$n; $i>0; $i--) {
$from = $folder->Items($i)->{'SenderEmailAddress'};
if ($from eq "sender@myemail.com") {
if ($folder->Items($i)->{'Unread'}) {
$folder->Items($i)->{'Unread'}=0;
+ #<--- this works
print "Is it? before - ".$folder->Items($i)->{'IsMarkedAsT
+ask'}."\n"; #<--- always returns 0
$folder->Items($i)->MarkAsTask(0);
+ #<--- I don't think this works
print "Is it? after - ".$folder->Items($i)->{'IsMarkedAsT
+ask'}."\n"; #<--- always returns 0
print "Cats before: ".$folder->Items($i)->Categories."\n";
while ($folder->Items($i)->Categories ne "NAC12182") {
$folder->Items($i)->{'Categories'}="NAC12182";
+ #<--- this doesn't work
}
print "Cats after: ".$folder->Items($i)->Categories."\n";
}
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.