Commit d638910b authored by Carsten  Rose's avatar Carsten Rose
Browse files

#4255 / Attachments fuer 'Email'

 Manual.rst: description of new options for MAIL_LOG and Report/sendmail.
 sendEmail: added new perl script.
 Report.php: $mailarr renamed to $mailConfig. convertToken() updated.
 Sendmail.php: commented mb_send_mail(). New sendEmail().
 Config.php: new options MAIL_LOG.
 Store.php: Update SUSTEM_SEND_E_MAIL
parent 7b497c32
......@@ -68,7 +68,7 @@ Preparation for Ubuntu 14.04::
Preparation for Ubuntu 16.04::
sudo apt install php7.0-intl
sudo apt install pdftk libxrender1 file # for file upload, PDF and 'HTML to PDF' (wkhtmltopdf)
sudo apt install pdftk libxrender1 file pdf2svg # for file upload, PDF and 'HTML to PDF' (wkhtmltopdf), PDF split
.. _wkhtml:
......@@ -238,11 +238,15 @@ config.qfq.ini
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| DB_INDEX_QFQ | DB_INDEX_QFQ = 1 | Optional. Default: 1. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SQL_LOG | SQL_LOG=sql.log | Filename to log SQL commands: relative to <ext_dir> or absolute. |
| SQL_LOG | SQL_LOG=../../sql.log | Filename to log SQL commands: relative to <ext_dir> or absolute. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SQL_LOG_MODE | SQL_LOG_MODE=modify | *all*: every statement will be logged - this might a lot. |
| | | *modify*: log only statements who change data. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| MAIL_LOG | SQL_LOG=../../mail.log | Filename to log `sendEmail` commands: relative to <ext_dir> or absolute. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SEND_E_MAIL_OPTIONS | SEND_E_MAIL_OPTIONS="-o tls=yes" | General options. Check: http://caspian.dotconf.net/menu/Software/SendEmail |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | FE - Possible values: yes|no|auto|download. For 'auto': If a BE User is |
| | | logged in, a debug information will be shown on the FE. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
......@@ -3357,6 +3361,8 @@ Type: sendmail
* *sendMailFrom* - Sender of the email. Optional: 'realname <john@doe.com>'. **Mandatory**.
* *sendMailSubject* - Subject of the email.
* *sendMailReplyTo* - Reply this email address. Optional: 'realname <john@doe.com>'.
* *sendMailAttachment* - List of files to attach to the mail. Multiple files separated by comma.
* *sendMailHeader* - Specify custom header.
* *sendMailFlagAutoSubmit* - **on|off** - If 'on' (default), the mail contains the header
'Auto-Submitted: auto-send' - this suppress a) OoO replies, b) forwarding of emails.
* *sendMailGrId* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
......@@ -5224,59 +5230,59 @@ Send text emails. Every mail will be logged in the table `mailLog`.
::
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow|a:off|g:1|x:2|y:3|z:4" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow|A:off|g:1|x:2|y:3|z:4" AS _sendmail
..
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|***Token** | **Parameter** |**Description** |**Required**|
+============================================================+==========================================================================================+============+
| t | email[,email] |Comma-separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| f | FROM:email |Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| s | subject |Subject of the email | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| b | body |Message | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| F | REPLY-TO:email |Email address to reply to (if different from sender) | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| a | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| c | email[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| B | mail[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
|***Token** | **Parameter** |**Description** |**Required**|
+===+========================================+==================================================================================================+============+
| f | FROM:email |**FROM**: Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| t | email[,email] |**TO**: Comma separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| c | email[,email] |**CC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| B | email[,email] |**BCC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| r | REPLY-TO:email |**Reply-to**: Email address to reply to (if different from sender) | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| s | Subject |**Subject**: Subject of the email | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| b | Body |**Body**: Message | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| h | Header |**Custom Header**: Separate multiple header with \r\n | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| a | Attachment |**Attachment**: Comma separated list of filenames to attach to the mail | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| A | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
**Minimal Example**
::
10.sql = SELECT "john.doe@example.com|company@example.com|Latest News|The new version is now available." AS _sendmail
10.sql = SELECT "t:john.doe@example.com|f:company@example.com|s:Latest News|b:The new version is now available." AS _sendmail
..
This will send an email with subject *Latest News* from company@example.com to john.doe@example.com.
**Advanced Examples**
::
10.sql = SELECT "customer1@example.com,Firstname Lastname <customer2@example.com>, Firstname Lastname <customer3@example.com>|company@example.com|Latest News|The new version is now available.|sales@example.com|on|101|222|ceo@example.com|backup@example.com" AS _sendmail
10.sql = SELECT "t:customer1@example.com,Firstname Lastname <customer2@example.com>, Firstname Lastname <customer3@example.com>|
f:company@example.com|s:Latest News|b:The new version is now available.|r:sales@example.com|A:on|g:101|x:222|c:ceo@example.com|B:backup@example.com" AS _sendmail
..
This will send an email with subject *Latest News* from company@example.com to customer1, customer2 and customer3 by
......
......@@ -23,6 +23,9 @@ SQL_LOG = ../../sql.log
; all|modify|error|none
SQL_LOG_MODE = modify
;MAIL_LOG = ../../mail.log
;SEND_E_MAIL_OPTIONS = "-o ... " - check http://caspian.dotconf.net/menu/Software/SendEmail
; [auto|yes|no][,download]. 'auto': if BE User is logged in the value will be replaced by 'yes', else 'no'. Additional choose 'download'.
SHOW_DEBUG_INFO = auto
......
#!/usr/bin/perl -w
##############################################################################
## sendEmail
## Written by: Brandon Zehm <caspian@dotconf.net>
##
## License:
## sendEmail (hereafter referred to as "program") is free software;
## you can redistribute it and/or modify it under the terms of the GNU General
## Public License as published by the Free Software Foundation; either version
## 2 of the License, or (at your option) any later version.
## When redistributing modified versions of this source code it is recommended
## that that this disclaimer and the above coder's names are included in the
## modified code.
##
## Disclaimer:
## This program is provided with no warranty of any kind, either expressed or
## implied. It is the responsibility of the user (you) to fully research and
## comprehend the usage of this program. As with any tool, it can be misused,
## either intentionally (you're a vandal) or unintentionally (you're a moron).
## THE AUTHOR(S) IS(ARE) NOT RESPONSIBLE FOR ANYTHING YOU DO WITH THIS PROGRAM
## or anything that happens because of your use (or misuse) of this program,
## including but not limited to anything you, your lawyers, or anyone else
## can dream up. And now, a relevant quote directly from the GPL:
##
## NO WARRANTY
##
## 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
## FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
## OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
## PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
## OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
## TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
## PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
## REPAIR OR CORRECTION.
##
##############################################################################
use strict;
use IO::Socket;
########################
## Global Variables ##
########################
my %conf = (
## General
"programName" => $0, ## The name of this program
"version" => '1.56', ## The version of this program
"authorName" => 'Brandon Zehm', ## Author's Name
"authorEmail" => 'caspian@dotconf.net', ## Author's Email Address
"timezone" => '+0000', ## We always use +0000 for the time zone
"hostname" => 'changeme', ## Used in printmsg() for all output (is updated later in the script).
"debug" => 0, ## Default debug level
"error" => '', ## Error messages will often be stored here
## Logging
"stdout" => 1,
"logging" => 0, ## If this is true the printmsg function prints to the log file
"logFile" => '', ## If this is specified (form the command line via -l) this file will be used for logging.
## Network
"server" => 'localhost', ## Default SMTP server
"port" => 25, ## Default port
"bindaddr" => '', ## Default local bind address
"alarm" => '', ## Default timeout for connects and reads, this gets set from $opt{'timeout'}
"tls_client" => 0, ## If TLS is supported by the client (us)
"tls_server" => 0, ## If TLS is supported by the remote SMTP server
## Email
"delimiter" => "----MIME delimiter for sendEmail-" ## MIME Delimiter
. rand(1000000), ## Add some randomness to the delimiter
"Message-ID" => rand(1000000) . "-sendEmail", ## Message-ID for email header
);
## This hash stores the options passed on the command line via the -o option.
my %opt = (
## Addressing
"reply-to" => '', ## Reply-To field
## Message
"message-file" => '', ## File to read message body from
"message-header" => '', ## Additional email header line(s)
"message-format" => 'normal', ## If "raw" is specified the message is sent unmodified
"message-charset" => 'iso-8859-1', ## Message character-set
"message-content-type" => 'auto', ## auto, text, html or an actual string to put into the content-type header.
## Network
"timeout" => 60, ## Default timeout for connects and reads, this is copied to $conf{'alarm'} later.
"fqdn" => 'changeme', ## FQDN of this machine, used during SMTP communication (is updated later in the script).
## eSMTP
"username" => '', ## Username used in SMTP Auth
"password" => '', ## Password used in SMTP Auth
"tls" => 'auto', ## Enable or disable TLS support. Options: auto, yes, no
);
## More variables used later in the program
my $SERVER;
my $CRLF = "\015\012";
my $subject = '';
my $header = '';
my $message = '';
my $from = '';
my @to = ();
my @cc = ();
my @bcc = ();
my @attachments = ();
my @attachments_names = ();
## For printing colors to the console
my ${colorRed} = "\033[31;1m";
my ${colorGreen} = "\033[32;1m";
my ${colorCyan} = "\033[36;1m";
my ${colorWhite} = "\033[37;1m";
my ${colorNormal} = "\033[m";
my ${colorBold} = "\033[1m";
my ${colorNoBold} = "\033[0m";
## Don't use shell escape codes on Windows systems
if ($^O =~ /win/i) {
${colorRed} = ${colorGreen} = ${colorCyan} = ${colorWhite} = ${colorNormal} = ${colorBold} = ${colorNoBold} = "";
}
## Load IO::Socket::SSL if it's available
eval { require IO::Socket::SSL; };
if ($@) { $conf{'tls_client'} = 0; }
else { $conf{'tls_client'} = 1; }
#############################
## ##
## FUNCTIONS ##
## ##
#############################
###############################################################################################
## Function: initialize ()
##
## Does all the script startup jibberish.
##
###############################################################################################
sub initialize {
## Set STDOUT to flush immediatly after each print
$| = 1;
## Intercept signals
$SIG{'QUIT'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
$SIG{'INT'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
$SIG{'KILL'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
$SIG{'TERM'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
## ALARM and HUP signals are not supported in Win32
unless ($^O =~ /win/i) {
$SIG{'HUP'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
$SIG{'ALRM'} = sub { quit("EXITING: Received SIG$_[0]", 1); };
}
## Fixup $conf{'programName'}
$conf{'programName'} =~ s/(.)*[\/,\\]//;
$0 = $conf{'programName'} . " " . join(" ", @ARGV);
## Fixup $conf{'hostname'} and $opt{'fqdn'}
if ($opt{'fqdn'} eq 'changeme') { $opt{'fqdn'} = get_hostname(1); }
if ($conf{'hostname'} eq 'changeme') { $conf{'hostname'} = $opt{'fqdn'}; $conf{'hostname'} =~ s/\..*//; }
return(1);
}
###############################################################################################
## Function: processCommandLine ()
##
## Processes command line storing important data in global vars (usually %conf)
##
###############################################################################################
sub processCommandLine {
############################
## Process command line ##
############################
my @ARGS = @ARGV; ## This is so later we can re-parse the command line args later if we need to
my $numargv = @ARGS;
help() unless ($numargv);
my $counter = 0;
for ($counter = 0; $counter < $numargv; $counter++) {
if ($ARGS[$counter] =~ /^-h$/i) { ## Help ##
help();
}
elsif ($ARGS[$counter] eq "") { ## Ignore null arguments
## Do nothing
}
elsif ($ARGS[$counter] =~ /^--help/) { ## Topical Help ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
helpTopic($ARGS[$counter]);
}
else {
help();
}
}
elsif ($ARGS[$counter] =~ /^-o$/i) { ## Options specified with -o ##
$counter++;
## Loop through each option passed after the -o
while ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
if ($ARGS[$counter] !~ /(\S+)=(\S.*)/) {
printmsg("WARNING => Name/Value pair [$ARGS[$counter]] is not properly formatted", 0);
printmsg("WARNING => Arguments proceeding -o should be in the form of \"name=value\"", 0);
}
else {
if (exists($opt{$1})) {
if ($1 eq 'message-header') {
$opt{$1} .= $2 . $CRLF;
}
else {
$opt{$1} = $2;
}
printmsg("DEBUG => Assigned \$opt{} key/value: $1 => $2", 3);
}
else {
printmsg("WARNING => Name/Value pair [$ARGS[$counter]] will be ignored: unknown key [$1]", 0);
printmsg("HINT => Try the --help option to find valid command line arguments", 1);
}
}
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-f$/) { ## From ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) { $from = $ARGS[$counter]; }
else { printmsg("WARNING => The argument after -f was not an email address!", 0); $counter--; }
}
elsif ($ARGS[$counter] =~ /^-t$/) { ## To ##
$counter++;
while ($ARGS[$counter] && ($ARGS[$counter] !~ /^-/)) {
if ($ARGS[$counter] =~ /[;,]/) {
push (@to, split(/[;,]/, $ARGS[$counter]));
}
else {
push (@to,$ARGS[$counter]);
}
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-cc$/) { ## Cc ##
$counter++;
while ($ARGS[$counter] && ($ARGS[$counter] !~ /^-/)) {
if ($ARGS[$counter] =~ /[;,]/) {
push (@cc, split(/[;,]/, $ARGS[$counter]));
}
else {
push (@cc,$ARGS[$counter]);
}
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-bcc$/) { ## Bcc ##
$counter++;
while ($ARGS[$counter] && ($ARGS[$counter] !~ /^-/)) {
if ($ARGS[$counter] =~ /[;,]/) {
push (@bcc, split(/[;,]/, $ARGS[$counter]));
}
else {
push (@bcc,$ARGS[$counter]);
}
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-m$/) { ## Message ##
$counter++;
$message = "";
while ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
if ($message) { $message .= " "; }
$message .= $ARGS[$counter];
$counter++;
} $counter--;
## Replace '\n' with $CRLF.
## This allows newlines with messages sent on the command line
$message =~ s/\\n/$CRLF/g;
}
elsif ($ARGS[$counter] =~ /^-u$/) { ## Subject ##
$counter++;
$subject = "";
while ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
if ($subject) { $subject .= " "; }
$subject .= $ARGS[$counter];
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-s$/) { ## Server ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
$conf{'server'} = $ARGS[$counter];
if ($conf{'server'} =~ /:/) { ## Port ##
($conf{'server'},$conf{'port'}) = split(":",$conf{'server'});
}
}
else { printmsg("WARNING - The argument after -s was not the server!", 0); $counter--; }
}
elsif ($ARGS[$counter] =~ /^-b$/) { ## Bind Address ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
$conf{'bindaddr'} = $ARGS[$counter];
}
else { printmsg("WARNING - The argument after -b was not the bindaddr!", 0); $counter--; }
}
elsif ($ARGS[$counter] =~ /^-a$/) { ## Attachments ##
$counter++;
while ($ARGS[$counter] && ($ARGS[$counter] !~ /^-/)) {
push (@attachments,$ARGS[$counter]);
$counter++;
} $counter--;
}
elsif ($ARGS[$counter] =~ /^-xu$/) { ## AuthSMTP Username ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
$opt{'username'} = $ARGS[$counter];
}
else {
printmsg("WARNING => The argument after -xu was not valid username!", 0);
$counter--;
}
}
elsif ($ARGS[$counter] =~ /^-xp$/) { ## AuthSMTP Password ##
$counter++;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) {
$opt{'password'} = $ARGS[$counter];
}
else {
printmsg("WARNING => The argument after -xp was not valid password!", 0);
$counter--;
}
}
elsif ($ARGS[$counter] =~ /^-l$/) { ## Logging ##
$counter++;
$conf{'logging'} = 1;
if ($ARGS[$counter] && $ARGS[$counter] !~ /^-/) { $conf{'logFile'} = $ARGS[$counter]; }
else { printmsg("WARNING - The argument after -l was not the log file!", 0); $counter--; }
}
elsif ($ARGS[$counter] =~ s/^-v+//i) { ## Verbosity ##
my $tmp = (length($&) - 1);
$conf{'debug'} += $tmp;
}
elsif ($ARGS[$counter] =~ /^-q$/) { ## Quiet ##
$conf{'stdout'} = 0;
}
else {
printmsg("Error: \"$ARGS[$counter]\" is not a recognized option!", 0);
help();
}
}
###################################################
## Verify required variables are set correctly ##
###################################################
## Make sure we have something in $conf{hostname} and $opt{fqdn}
if ($opt{'fqdn'} =~ /\./) {
$conf{'hostname'} = $opt{'fqdn'};
$conf{'hostname'} =~ s/\..*//;
}
if (!$conf{'server'}) { $conf{'server'} = 'localhost'; }
if (!$conf{'port'}) { $conf{'port'} = 25; }
if (!$from) {
quit("ERROR => You must specify a 'from' field! Try --help.", 1);
}
if ( ((scalar(@to)) + (scalar(@cc)) + (scalar(@bcc))) <= 0) {
quit("ERROR => You must specify at least one recipient via -t, -cc, or -bcc", 1);
}
## Make sure email addresses look OK.
foreach my $addr (@to, @cc, @bcc, $from, $opt{'reply-to'}) {
if ($addr) {
if (!returnAddressParts($addr)) {
printmsg("ERROR => Can't use improperly formatted email address: $addr", 0);
printmsg("HINT => Try viewing the extended help on addressing with \"--help addressing\"", 1);
quit("", 1);
}
}
}
## Make sure all attachments exist.
foreach my $file (@attachments) {
if ( (! -f $file) or (! -r $file) ) {
printmsg("ERROR => The attachment [$file] doesn't exist!", 0);
printmsg("HINT => Try specifying the full path to the file or reading extended help with \"--help message\"", 1);
quit("", 1);
}
}
if ($conf{'logging'} and (!$conf{'logFile'})) {
quit("ERROR => You used -l to enable logging but didn't specify a log file!", 1);
}
if ( $opt{'username'} ) {
if (!$opt{'password'}) {
## Prompt for a password since one wasn't specified with the -xp option.
$SIG{'ALRM'} = sub { quit("ERROR => Timeout waiting for password inpupt", 1); };
alarm(60) if ($^O !~ /win/i); ## alarm() doesn't work in win32
print "Password: ";
$opt{'password'} = <STDIN>; chomp $opt{'password'};
if (!$opt{'password'}) {
quit("ERROR => A username for SMTP authentication was specified, but no password!", 1);
}
}
}
## Validate the TLS setting
$opt{'tls'} = lc($opt{'tls'});
if ($opt{'tls'} !~ /^(auto|yes|no)$/) {
quit("ERROR => Invalid TLS setting ($opt{'tls'}). Must be one of auto, yes, or no.", 1);
}
## If TLS is set to "yes", make sure sendEmail loaded the libraries needed.
if ($opt{'tls'} eq 'yes' and $conf{'tls_client'} == 0) {
quit("ERROR => No TLS support! SendEmail can't load required libraries. (try installing Net::SSLeay and IO::Socket::SSL)", 1);
}
## Return 0 errors
return(0);
}