Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

moving emails between folders with Win32::OLE

by RayRay459 (Pilgrim)
on May 14, 2002 at 15:07 UTC ( [id://166457]=perlquestion: print w/replies, xml ) Need Help??

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

Oh Wise Ones, I Am again in need of your assistance.
I have this code that will read emails in a public folder and parse through them looking for strings. I am stuck though and have not found any information on how to move them to another folder. Can Anyone please help? It would me much appreciated. (I've done google searches and looked at www.microsoft.com/outlookdev and i can't really find what i'm looking for.) Thanks again,
Ray
#!D:/perl/bin/perl -w use strict; use Win32::OLE qw(in with); use Win32::OLE::Const 'Microsoft Outlook'; my($Outlook, $ol, $namespace, $Folder1, $Folder2, $Folder3, $Folder4, +$Folder5, $item, $body); $|++; $Win32::OLE::Warn = 3; $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') or Win32 +::OLE->new('Outlook.Application', 'Quit'); $ol = Win32::OLE::Const->Load($Outlook); $namespace = $Outlook->GetNameSpace("MAPI") or die "Can't open MAPI na +mespace: $!"; $Folder1 = $namespace->Folders("Public Folders"); $Folder2 = $Folder1->Folders("All Public Folders"); $Folder3 = $Folder2->Folders("Ops"); $Folder4 = $Folder3->Folders("Search"); $Folder5 = $Folder4->Folders("Been Read"); foreach $item (in $Folder4->{Items}){ $body = $item->{Body}; if($body =~ /ALL\s+TESTS\s+SUCCESSFUL/i){ print $item->{Subject} . " ok\n"; # This is where i would want a statement to move the item to $Fold +er5 }elsif($body =~ /Ending/i && $body !~/Abort/i){ print $item->{Subject} . " ok\n"; }else{ print "possible error on indexer for $item->{Subject}.\n"; next; } }

Replies are listed 'Best First'.
Re: moving emails between folders with Win32::OLE
by strat (Canon) on May 14, 2002 at 15:22 UTC
    If I remember correctly, you need two objects in your hand: one for the message, and another object for the target-folder.
    Then there must be a method for the message called $messageObject->MoveTo($targetFolderObject).

    But I'll look it up tonight and post its exact name and usaege (it was about in 1998 when I've last worked with perl and Outlook/Exchange via Win32::OLE (MAPI/CDO)).

    Best regards,
    perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

      Thanks for the advice. Very Much appreciated. I attempted to use this line and got an error:
      $item->MoveTo($Folder5);
      C:\scripts\perl\email>getsearchemail.pl Attributes caty3 Update ok SEARCH: roadster active-desc2 Indexing Results ok Win32::OLE(0.1501) error 0x80020006: "Unknown name" in GetIDsOfNames of "MoveTo" at C:\scripts\perl\email\getSearchEm +ail.pl lin e 28
      Did i understand what you said correctly?
        Sorry, was my error. MoveTo requires the FolderID or StoreID as String. http://msdn.microsoft.com/ -> search for CDO and MoveTo says about the following:
        $item->MoveTo( $Folder5->{FolderID} );
        or:
        $item->MoveTo( $Folder5->{StoreID} );

        Best regards,
        perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://166457]
Approved by particle
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-19 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found