### Sends e-mail message using the Net::SMTP module
###
sub net_smtp_send {
my ($send_hashes, $text, $par, $debug) = @_;
$par = email_configuration_read() if ! defined $par;
my ($smtp, $status) =
eval '
use Net::SMTP;
my $status = 0;
my $smtp = undef;
if ($smtp = Net::SMTP->new($par->{"SMTP"}, Timeout => 15)) {
$status = 1;
}
($smtp, $status);
';
if ($@) {
error_message("SMTP configuration error", "[0] Error executing Net::SMTP (error is: $@)! Make sure Net::SMTP is installed on your server.") if $debug;
return 0;
}
if (!$status) {
error_message("SMTP connection error", "[1] Error connecting to $par->{'SMTP'}! Be sure you've given the correct name for the SMTP server, that the SMTP server is turned on, and that the SMTP server actually has SMTP service running on it!") if $debug;
return 0;
}
my $fr = "\"$par->{fromname}\"";
$fr .= " <$par->{fromaddr}>" if $par->{fromaddr};
$fr .= " <null\@null.null>" if ! $par->{fromaddr};
my $dataX = "X-Mailer: Discus";
$dataX .= " Pro" if $DCONF->{pro};
$dataX .= " <$DCONF->{html_url}>\n";
foreach my $r (@{ $send_hashes }) {
my $d = $dataX;
$d .= "Content-Type: text/html; charset=$DCONF->{mail_charset}\n" if $r->{html};
$d .= "Content-Type: text/plain; charset=$DCONF->{mail_charset}\n" if ! $r->{html};
if (!$smtp->mail($par->{fromaddr})) {
error_message("SMTP send error", "[2] Error sending data to $par->{'SMTP'}: " . $smtp->message()) if $debug;
return 0;
}
if (!$smtp->to($r->{to})) {
error_message("SMTP send error", "[3] Error sending data to [$r->{to}] $par->{'SMTP'}: " . $smtp->message()) if $debug;
error_message("SMTP configuration error", "[0] Error executing Mail::Sendmail (error is: $@)! Make sure Mail::Sendmail is installed on your server.") if $debug;
log_error("mailer.pl", "command_line_send", "Send failed for [$cmdline] $!") if ! $debug;
error_message("Send Failed", "Failed to execute command '$cmdline': $!") if $debug;
return 0;
}
}
unlink ($tempfile);
return 1;
}
###
### windows_process_send
###
### Sends an e-mail message with the Win32::Process module
###
sub windows_process_send {
my ($mail_prog, $cmdline, $cwd, $debug) = @_;
my $code = eval '
use Win32::Process;
use Win32;
my $ProcessObj = undef;
my $ExitCode = undef;
if (Win32::Process::Create($ProcessObj, "$mail_prog", "$cmdline", 0, DETACHED_PROCESS, $cwd)) {
$ProcessObj->Wait(INFINITE);
$ProcessObj->GetExitCode( $ExitCode );
$ExitCode;
} else {
error_message("Windows Process Creation Error", Win32::FormatMessage(Win32::GetLastError()) . "<P>Command line:<PRE>$cmdline</PRE><P>CWD:<PRE>$cwd</PRE>") if $debug;
log_error("mailer.pl", "windows_process_send", Win32::FormatMessage(Win32::GetLastError())) if ! $debug;
0;
}
';
return $code;
}
###
### mailer_error
###
### Prints error to log or to screen depending on whether or not you are debugging