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

Glorius Brothers and Sisters....

I'm working on a script that will allow Users to open and view an Outlook .msg file. MS Outlook and Outlook Express allow Users to to drag and drop an email to a directory and create a .msg file that contains the email and any attachments. The publishing company where I work has decided that this small file will form the basis of an ad tracking system, for better or worse. Currently the management of these files is completely manual. The current script will form part of a larger Perl App that will provide some automation and tracking.

I've tried using Win32::Process to open the file in Outlook Express but without luck. The sample code is below. I can launch OE fine, the file itself will not open however. It will open if I just double click the file sitting on the desktop it so I know OE is able to view it.

I've also tried Win32::OLE. Regrettably it's not working. The goal here is to simply open the .msg file for viewing in Outlook. I do not require data from the email itself.

Any thoughts or hints would be appreciated.

I am using ActiveState Perl 5.8.7 on Windows XP. The solution will have to work on both XP and Win2000.

#Win32::Process sample sub ViewEmail{ my $Path = "c:\\documents and settings\\p court\\desktop"; my $Outlook = "c:\\program files\\Outlook Express\\MSIMN.exe"; my $ProcessObj; my $file = "VolleyballBC"; if($Outlook){ chdir $Path; Win32::Process::Create( $ProcessObj, $Outlook, "MSIMN $file", 1, NORMAL_PRIORITY_CLASS, ".") || die ! "no can do"; } $ProcessObj->Suspend(); $ProcessObj->Resume(); }

Replies are listed 'Best First'.
Re: Outlook Express & Perl
by Corion (Patriarch) on Sep 20, 2007 at 06:38 UTC

    OE doesn't really have automation features from what I remember. But you might be able to reproduce what happens when you double-click a .msg file by using the start command:

    my $file = "VolleyballBC.msg"; my $cmd = qq{"$Outlook" "$Path\\$file"}; system($cmd) == 0 or die "Couldn't launch '$cmd': $!/$?";
      #3333.. thanks for the reply...your adaptation works similar to the Win32::Process sample - it opens OE but not the file...I'm beginning to wonder if the file extension is incorrect for OE....when the file is dragged and dropped form OE to the desktop it creates a file without an extension...I've tried no extension and .msg (which is the extension that MS Outlook does)...still tinkering.. cheers pc
        I did determine that OE files dragged and dropped onto the desktop or in a directory have an extension of .eml rather than .msg, which is what Outlook 2003 uses. Still, makes no difference when scripting to open in OE...I'm off to work to try with Outlook 2003
Re: Outlook Express & Perl
by ikegami (Patriarch) on Sep 20, 2007 at 17:04 UTC

    If you want to open a file with its default document handler, use start:

    system(qq{start "" "$msg_file"});