#!/usr/bin/perl use strict; use warnings; use POSIX; use Win32::OLE; open my $source, "<", "//reports/test.txt" or die "cannot open file: $!\n"; my $ies_details; while( <$source> ) { next unless substr $source,11,4 =~ /\d{4}/; next unless substr $source,79,10 =~ /\d{10}/; $ies_details .= $_; } my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application'); my $mailitem = $Outlook->CreateItem(0) or die "Outlook is not running, cannot send mail.\n"; my $procdate = POSIX::strftime('%m/%d/%Y %H:%M', localtime); $mailitem->{'To'} = 'test@yahoo.com'; $mailitem->{'Cc'} = 'test@test.com'; $mailitem->{'Subject'} = 'Summary Report ' . $procdate; $mailitem->{'Body'} = "Below is a summary\n\n" . "-----------------------------------------\n\n" . $ies_details; $mailitem->{'Importance'} = 0; # 2=high, 1=normal, 0=low $mailitem->Send;