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

I am trying to write a perl script to edit the body of an Outlook email message to tart it up before I send it. I can connect to Outlook, detect open emails and even get at the body text (see below for my code so far) but my problem is that the RTF-ness of the message is avoiding me. In fact, it's laughing at me saying, "Come and get me... no I didn't think you could!"

Please help me to teach it a lesson. I need to add/replace unformatted text in the message body with nicely coloured text, change fonts/sizes etc.

So far I have (pitiful I know)...

#!perl use strict; use warnings; use Win32::OLE 'in'; use Win32::OLE::Const 'Microsoft Outlook'; my $server = Win32::OLE->GetActiveObject('Outlook.Application'); for my $inspector ( in $server->Inspectors ) { if ( $inspector->CurrentItem->Class != olMail ) { print "not an email, skipping...\n"; next; } elsif ( $inspector->EditorType != olEditorRTF ) { print "not rich text format (RTF), skipping...\n"; next; } else { print "processing...\n"; # here's the body # but i need the textbox or something # and this is as far as i have got $inspector->CurrentItem->Body; } }
Any help will be most gratefully received,
   larryk                                          
perl -le "s,,reverse killer,e,y,rifle,lycra,,print"

Replies are listed 'Best First'.
Re: Message Editing in Outlook using Win32::OLE
by larryk (Friar) on Oct 05, 2001 at 18:42 UTC
    Hahahahahahahahahahahahahahahahaha... you're not laughing now RTefffF! I gotcha, and I can prove it...
    $inspector->CurrentItem->SaveAs( 'c:\temp\message.rtf', olRTF );
    Using RTF::Document and RTF::Parser I should be able to edit the file into what I want. My only dilemma now is how to get my new RTF back into the current message. I suppose I could dump it and create a whole new message. But that's a pain if there are attachments. And I don't know how to import the RTF (with all its codes and everything) into a new message any more than I know how to replace the existing message with my new content.

    Again, any help will be met with joyous abandon

       larryk                                          
    perl -le "s,,reverse killer,e,y,rifle,lycra,,print"
      Hi Larryk,

      Perhaps could I suggest you use HTML formatting instead of rich text and then access the html code throught the property htmlbody rather than solely body... It's much easier and at least everyone recognizes HTML, which isn't so true about rtf...
      Good luck and let me know if you've taught rtf the lesson it needs...