N
Naji
OK, I have never used Perl before, and FAQ's have confused me quite a
bit. I am not understanding some of the Perl syntax. But anyhow, I
think I have the code, I just need to combine it. At work, we need a
Perl script that automatically sends an e-mail with an attachment every
morning. Using a macro with a scheduled running of Outlook is crashing
too much, so using Perl was brought up as a good alternative. Here is
what our current code is:
&CheckMail($ReturnCode);
sub CheckMail {
my $ReturnCode = shift;
use Mail::Sender;
$msgfrom = qw(PPS-Server) ;
$msgsubject = qq(Production Scheduler);
if ( $ReturnCode == 0 ) {
$msg = "The Production Scheduler has completed successfully " ;
} elsif ( $ReturnCode == 1 ) {
$msg = "The Production Scheduler has completed with errors" ;
} else {
$msg = "The Production Scheduler has completed with warnings" ;
}
$sender = new Mail::Sender {smtp => "EX1",
from => "$msgfrom"};
@ppsmail = qw (
(e-mail address removed)
);
chdir 'D:/PPSPROD/LOG' or die "EEEEEEEEE =====> Can\'t open
D:/PPSPROD/LOG \n";
foreach $msgto (@ppsmail) {
$sender->MailFile({to => "$msgto",
subject => "$msgsubject",
msg => "$msg",
file => "schsub.log"});
}
}
And then, thanks to this forum, I have syntax for checking whether the
file is worth sending...wether it's been updated that day. That code is
as follows:
$currentTime = time();
($device, $inode, $mode, $numOfHardLinks, $userId, $groupId,
$deviceIdentifier, $size, $lastAccessed, $lastModified,
$inodeLastChanged) = stat($attachment);
if($lastModified + 43200 >= $currentTime) { # 43200 is the number of
seconds in 12 hours.
# Attachment was modified in the last 12 hours
bit. I am not understanding some of the Perl syntax. But anyhow, I
think I have the code, I just need to combine it. At work, we need a
Perl script that automatically sends an e-mail with an attachment every
morning. Using a macro with a scheduled running of Outlook is crashing
too much, so using Perl was brought up as a good alternative. Here is
what our current code is:
&CheckMail($ReturnCode);
sub CheckMail {
my $ReturnCode = shift;
use Mail::Sender;
$msgfrom = qw(PPS-Server) ;
$msgsubject = qq(Production Scheduler);
if ( $ReturnCode == 0 ) {
$msg = "The Production Scheduler has completed successfully " ;
} elsif ( $ReturnCode == 1 ) {
$msg = "The Production Scheduler has completed with errors" ;
} else {
$msg = "The Production Scheduler has completed with warnings" ;
}
$sender = new Mail::Sender {smtp => "EX1",
from => "$msgfrom"};
@ppsmail = qw (
(e-mail address removed)
);
chdir 'D:/PPSPROD/LOG' or die "EEEEEEEEE =====> Can\'t open
D:/PPSPROD/LOG \n";
foreach $msgto (@ppsmail) {
$sender->MailFile({to => "$msgto",
subject => "$msgsubject",
msg => "$msg",
file => "schsub.log"});
}
}
And then, thanks to this forum, I have syntax for checking whether the
file is worth sending...wether it's been updated that day. That code is
as follows:
$currentTime = time();
($device, $inode, $mode, $numOfHardLinks, $userId, $groupId,
$deviceIdentifier, $size, $lastAccessed, $lastModified,
$inodeLastChanged) = stat($attachment);
if($lastModified + 43200 >= $currentTime) { # 43200 is the number of
seconds in 12 hours.
# Attachment was modified in the last 12 hours