Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grab Email and put message in text file

Status
Not open for further replies.

evergreean43

Technical User
Joined
May 25, 2006
Messages
165
Location
US
I need to create a Perl script that will run on my local Windows 2000 workstation once a day and find in my Outlook 2003 Office Email the Subject: Journal. Then take the message from the email Journal and populate a text file with the message information.

Is this the right direction? I seem to get errors on my attempt:
Code:
use strict;
use warnings;

use Win32::OLE 'in';
use Win32::OLE::Const 'Microsoft Outlook'; 

my $outlook = Win32::OLE->GetActiveObject('Outlook.Application')
  or do {
    my $reason = Win32::FormatMessage(Win32::GetLastError());
    die "Cannot get active Outlook object: $reason";
  };

my $namespace = $outlook->GetNamespace('MAPI');

if (my $folder = $namespace->GetDefaultFolder(olFolderInbox)) {
    print $folder->Name, "\n";

    foreach my $email (in $folder->Items) {
        print "  ", $email->Subject, "\n" 
          if $email->Subject eq 'Build 50.2';

        open (REPORT, ">file.txt")||die "Can't open report file!\n";
        while ($line = <REPORT>) {
        print "$line\n"; #
}
close (REPORT);
    }
}
 

Code:
 print "  ", $email->Subject, "\n" 
          if $email->Subject eq 'Build 50.2'; --> Writing to the SCREEN, what is being stored in file.txt?

        open (REPORT, ">file.txt")||die "Can't open report file!\n"; -->What's in file.txt?
        while ($line = <REPORT>) {
 
On that note, something else that might be a problem:

Code:
open (REPORT, ">file.txt")||die "Can't open report file!\n";
[COLOR=red]while ($line = <REPORT>) {[/color]

You can't open a file for reading and writing at the same time. When you open a file for writing (the > flag there), it blanks out the contents of the file. So your while loop to read <REPORT> probably isn't reading anything but blank data.
 
Thanks,

I think my problem is with the modules on my Windows 2000 Server:
Code:
use Win32::OLE 'in';
use Win32::OLE::Const 'Microsoft Outlook';

I assume these dont come with the standard distribution of 5.8 and I will have to get them from CPAN?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top