Accessing Outlook mail via Mail::Outlook



Greeting.

I am trying to create a script that will search a user's outlook email and move any messages that mtahc a certain subject to a new folder. To accomplish this I found the Mail::Outlook module on CPAN that allows me to easily access the OLE Outlook calls via Win32::Ole.

My problem is this, the Mail::Outlook module does not have a specific method to move an email from one mailbox to another. I can display the email when my match occurs, but I cannot figure out how to move it.

Here is an example of my code that works just find to pop-up an display any messages in my mailbox that match :

use Mail::Outlook;
use strict;

# Open filehandle to Remedy report file
open (_TICKETS,'C:\TicketCounts\MyOpen.rep') or die "Cannot open C:\TicketCounts\MyOpen.rep : $!";
# Iterate through each line of the file
print "Obtaining list of open tickets from $remedyReportFile .... ";
while (<_TICKETS>){
# Add ticket number to array in csv format
push @myTickets, "$1" if m/CallT0000(\d+)/;
}
print " Ok.\n";
# Open an Outlook OLE connection
print "Opening connection to Outlook .... ";
my $outlook = new Mail::Outlook('') or die "Cannot create mail object\n";
# Change to the Support mail folder
my $folder = $outlook->folder('Inbox/Support') or die "Cannot create folder object\n";
# Read the 1st message
print " Ok.\n";
print "Searching messages for call ticket match .... " unless defined $bodyMatchString;
print "Searching messages for subject containing: call ticket matches and body containing: $bodyMatchString ... " if defined $bodyMatchString;
my $message = $folder->first();

# Iternate all messages in the folder
while ($message) {
# Strip the call ticket number out of the subject
my $callTicketNumber=$1 if $message->Subject() =~ m/CallT0000(\d+) /;
# If a call ticket number was found, compare against the user's open call tickets
if (defined $callTicketNumber) {
if ( (grep /$callTicketNumber/, @myTickets) ) {
$emailMatches++;
$message->Display;
}
}
}

Now, I want to change the $message->Display to a move operation. Searching the available OLE/COM Objects for Outlook via Microsoft's OLE/COM Viewer, I see that there is a move method for the mailItem CO class:

[id(0x0000f034), helpcontext(0x004de8b9)]
IDispatch* Move([in] MAPIFolder* DestFldr);

I tried editing the Outlook::Mesage.pm file (that stores the message display call) to add a call to this OLE method.

The 1st thing I did was to see if I could simply add a new su b to the PM file called moveMessage that in actually would simply display the messag the same way the display sub did:

sub moveMessage {
my ($self,%hash) = @_;

# pre-populate the fields, if hash
foreach my $field (@autosubs) {
$self->{$field} = $hash{$field} if($hash{$field});
}

# we need a basic message fields
return 0 unless($self->{To} && $self->{Subject} && $self->{Body});

# Build the message
$self->{message}->{To} = $self->{To};
$self->{message}->{Cc} = $self->{Cc} if($self->{Cc});
$self->{message}->{Bcc} = $self->{Bcc} if($self->{Bcc});
$self->{message}->{Subject} = $self->{Subject};
$self->{message}->{Body} = $self->{Body};

# Send the email
$self->{message}->Display();

return 1;
}

I thought this would be an easy 1st step, but come to find out, I am getting teh following error when I run this:

retrying default method at E:/Perl/site/lib/Win32/OLE/Lite.pm line 157, <_TICKETS> line 9.
Win32::OLE(0.1403) error 0x8002000e: "Invalid number of parameters"
in METHOD/PROPERTYGET "" at H:\outlook2.pl line 45

Now, I must confess that I am new to OLE and have limited exposure to Object Orientation. Can anyone point me in the right direction or show me some sample code that will move a message from one mailbox to another?

I have searched extensively for any existing code to do this, but all I have found are very limited and do not come close to accomplishing my goal.

I appreciate any help.

Thanks!
Jason
.



Relevant Pages

  • Re: Need more info...
    ... Her Display Name is Vikkie Lastname, Which is correct, her smtp address is ... in Outlook if I start typing a V, I ... > organization) to messages sent by the original mailbox will get sent to ... > reconnect it to User2. ...
    (microsoft.public.exchange.setup)
  • Re: Exchange mailbox losses/suppresses original sent to addresses
    ... Exchange mailbox shows only primary display name, ... IS THERE A WAY TO GET EXCHANGE 2003 TO DISPLAY THE ORIGINAL ... OF DISPLAYING ALL EMAIL AS SENT TO THE 'DISPLAY NAME' IN THE USER ACCOUNT ...
    (microsoft.public.exchange.admin)
  • Re: Changing a mailbox name
    ... When I go to AD Users and Computers I only see the name of the domain, ... display name, but this does not affect the mailbox. ... > editing the current entry.. ...
    (microsoft.public.windows.server.sbs)
  • Re: Auction Woes
    ... my alts before so I'm going to look into it. ... items in the same class before auctioning as well. ... Also, if you let too much cruft fill up your mailbox, you won't be able ... the display the first time. ...
    (alt.games.warcraft)
  • Re: Multiple Mailbox managment
    ... That is what I am afraid of; I would not want to put anything in the display ... the specific mailbox without having the information sent out on emails. ... I think what you need to do is to log into the new accounts using Outlook. ... mailboxes by name in Outlook that is not displayed on Outgoing email. ...
    (microsoft.public.windows.server.sbs)