Rev 201 | Blame | Last modification | View Log | Download | RSS feed
#! /usr/bin/env perl
# sendEmailScript
# Retrieves info from sysinfo-client and sends it to the server via
# smtp. It uses {sendEmailScriptLocation} to send the file (assumed
# to be Brandon Zehm's sendEmail.pl, dotconf.net), and utilizes
# the rest of $$parameters to figure out where things go.
#
# returns 1 on success, something other than 1 on failure
use warnings;
use strict;
our $VERSION = '1.1';
sub doit {
my ( $parameters, $message ) = @_;
my %CLIParams ;
$CLIParams{'-f'} = qq/$$parameters{'mailFrom'}/ if $$parameters{'mailFrom'};
$CLIParams{'-t'} = qq/$$parameters{'mailTo'}/ if $$parameters{'mailTo'};
$CLIParams{'-u'} = qq/$$parameters{'mailSubject'}/ if $$parameters{'mailSubject'};
$CLIParams{'-s'} = qq/$$parameters{'mailServer'}/ if $$parameters{'mailServer'};
$CLIParams{'-xu'} = qq/$$parameters{'smtpUser'}/ if $$parameters{'smtpUser'};
$CLIParams{'-xp'} = qq/$$parameters{'smtpPass'}/ if $$parameters{'smtpPass'};
$CLIParams{'-cc'} = qq/$$parameters{'mailCC'}/ if $$parameters{'mailCC'};
$CLIParams{'-bcc'}= qq/$$parameters{'mailBCC'}/ if $$parameters{'mailBCC'};
$CLIParams{'-l'} = qq/$$parameters{'logFile'}/ if $$parameters{'logFile'};
$CLIParams{'-a'} = qq/$$parameters{'attachment'}/ if $$parameters{'attachment'};
$CLIParams{'-o tls='} = qq/$$parameters{'tls'}/ if $$parameters{'tls'};
my $commandLine = $$parameters{'sendEmailScriptLocation'};
die "Could not find executable $commandLine in sendEmailScript\n" unless -x $commandLine;
foreach my $key ( keys %CLIParams ) {
# depending on whether the key ends in an = or not, we will or will not use a space
# between the key and the parameter
$commandLine .= $key =~ m/=$/ ? " $key'$CLIParams{$key}'" : " $key '$CLIParams{$key}'";
}
$commandLine .= ' ' . $$parameters{'otherCLParams'} if $$parameters{'otherCLParams'};
# print "$commandLine\n\n";
# print $message;
# return;
open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
print SENDMAIL $message;
if ( close SENDMAIL ) { # we got an error return from SENDMAIL
my $error = $? >> 8;
print "Error sending report; code was [$error]\n";
return $error;
} else {
return 1;
}
}
1;