2 |
rodolico |
1 |
#! /usr/bin/perl -w
|
|
|
2 |
|
|
|
3 |
my $application = 'sendEmail.pl'; # assumed to be located in the scripts directory
|
|
|
4 |
|
|
|
5 |
sub doit {
|
|
|
6 |
my ( $parameters, $message, $scriptDirectory ) = @_;
|
|
|
7 |
my %CLIParams ;
|
|
|
8 |
$CLIParams{'-f'} = qq/$$parameters{'mailFrom'}/ if $$parameters{'mailFrom'};
|
|
|
9 |
$CLIParams{'-t'} = qq/$$parameters{'mailTo'}/ if $$parameters{'mailTo'};
|
|
|
10 |
$CLIParams{'-u'} = qq/$$parameters{'mailSubject'}/ if $$parameters{'mailSubject'};
|
|
|
11 |
$CLIParams{'-s'} = qq/$$parameters{'mailServer'}/ if $$parameters{'mailServer'};
|
|
|
12 |
$CLIParams{'-xu'} = qq/$$parameters{'smtpUser'}/ if $$parameters{'smtpUser'};
|
5 |
rodolico |
13 |
$CLIParams{'-xp'} = qq/$$parameters{'smtpPass'}/ if $$parameters{'smtpPass'};
|
2 |
rodolico |
14 |
$CLIParams{'-cc'} = qq/$$parameters{'mailCC'}/ if $$parameters{'mailCC'};
|
|
|
15 |
$CLIParams{'-bcc'}= qq/$$parameters{'mailBCC'}/ if $$parameters{'mailBCC'};
|
|
|
16 |
$CLIParams{'-l'} = qq/$$parameters{'logFile'}/ if $$parameters{'logFile'};
|
5 |
rodolico |
17 |
$CLIParams{'-a'} = qq/$$parameters{'attachment'}/ if $$parameters{'attachment'};
|
|
|
18 |
$CLIParams{'-o tls='} = qq/$$parameters{'tls'}/ if $$parameters{'tls'};
|
2 |
rodolico |
19 |
|
5 |
rodolico |
20 |
|
2 |
rodolico |
21 |
$commandLine = $scriptDirectory . $application;
|
|
|
22 |
die "Could not find executable $commandLine in sendEmailScript\n" unless -x $commandLine;
|
|
|
23 |
foreach my $key ( keys %CLIParams ) {
|
5 |
rodolico |
24 |
# depending on whether the key ends in an = or not, we will or will not use a space
|
|
|
25 |
# between the key and the parameter
|
|
|
26 |
$commandLine .= $key =~ m/=$/ ? " $key'$CLIParams{$key}'" : " $key '$CLIParams{$key}'";
|
2 |
rodolico |
27 |
}
|
|
|
28 |
$commandLine .= ' ' . $$parameters{'otherCLParams'} if $$parameters{'otherCLParams'};
|
5 |
rodolico |
29 |
# print "$commandLine\n\n";
|
|
|
30 |
# print $message;
|
|
|
31 |
# return;
|
2 |
rodolico |
32 |
open SENDMAIL, "|$commandLine" or die "Could not open [$commandLine]: $!\n";
|
|
|
33 |
print SENDMAIL $message;
|
|
|
34 |
close SENDMAIL;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
1;
|