I am trying to write a script to delete attachments from items in my Outlook 2000 sentmail folder. Here is the code
use strict; use Win32::OLE; use Win32::OLE::Const 'Microsoft Outlook'; my $Folder; my $mailboxname = "Mailbox"; # set up OLE my $Outlook; eval {$Outlook = Win32::OLE->GetActiveObject('Outlook.Application')}; die "Outlook not installed" if $@; unless (defined $Outlook) { $Outlook = Win32::OLE->new('Outlook.Application', sub {$_[0]->Quit +;}) or die "Cannot start Outlook"; } my $ol = Win32::OLE::Const->Load($Outlook); my $namespace = $Outlook->GetNamespace("MAPI"); # open folder if ($ARGV[0]) { $Folder = $namespace->Folders($mailboxname)->Folders($ARGV[0]) || +die "Can't open folder $ARGV[0]\n"; } else { die "Usage: stripattachments.pl foldername\n"; } my $n = $Folder->Items->Count; # analyze messages print "$n messages\n\n"; for my $i (1..$n) { print "Message $i "; my $msg = $Folder->Items($i); my $attachments = $msg->attachments; if ($attachments->Count) { print "removing..."; while ($attachments->Count) { $attachments->Remove(1); } } print "\n"; } undef $Outlook;
It works great up until the last if block. When I watch it with the debugger, it seems to be working because it finds the messages with attachments, $attachments->Count does decrement as it goes through the while loop, and the while loop terminates. However when the script finished and I look in Outlook the attachments are still there. What am I doing wrong?

TIA.....Steve


In reply to Win32 Deleting Outlook Attachments 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.