diff --git a/etc/WebGUI.conf.original b/etc/WebGUI.conf.original index 68339db57..674c5cd63 100644 --- a/etc/WebGUI.conf.original +++ b/etc/WebGUI.conf.original @@ -161,6 +161,11 @@ # "emailOverride" : "joe@example.com", +# Set this value if you wish to bypass sending email to the mailserver alltogether. +# This will instead pipe email messages to the log, removing them from the queue normally + +# "emailToLog" : "1", + # By adding CIDR based subnets to the following array you can limit the # subnets by which users can turn admin mode on. diff --git a/lib/WebGUI/Mail/Send.pm b/lib/WebGUI/Mail/Send.pm index 25f70beb7..91ce75525 100644 --- a/lib/WebGUI/Mail/Send.pm +++ b/lib/WebGUI/Mail/Send.pm @@ -435,23 +435,33 @@ Sends the message via SMTP. Returns 1 if successful. =cut sub send { - my $self = shift; - my $mail = $self->getMimeEntity; - - my $status = 1; + my $self = shift; + my $session = $self->session; + my $log = $session->log; + + my $mail = $self->getMimeEntity; + my $smtpServer = $session->setting->get("smtpServer"); + my $status = 1; + if ($mail->head->get("To")) { - if ($self->session->setting->get("smtpServer") =~ /\/sendmail/) { - if (open(MAIL,"| ".$self->session->setting->get("smtpServer")." -t -oi -oem")) { + if ($session->config->get("emailToLog")){ + my $message = $mail->stringify; + $log->warn(qq{$message + \nTHIS MESSAGE WAS NOT SENT THROUGH THE MAIL SERVER. TO RE-ENABLE MAIL, DISABLE THE emailToLog SETTING IN THE CONFIG FILE. + }); + } + elsif ($smtpServer =~ /\/sendmail/) { + if (open(MAIL,"| ".$smtpServer." -t -oi -oem")) { $mail->print(\*MAIL); - close(MAIL) or $self->session->errorHandler->error("Couldn't close connection to mail server: ".$self->session->setting->get("smtpServer")); + close(MAIL) or $log->error("Couldn't close connection to mail server: ".$smtpServer); } else { - $self->session->errorHandler->error("Couldn't connect to mail server: ".$self->session->setting->get("smtpServer")); + $log->error("Couldn't connect to mail server: ".$smtpServer); $status = 0; } } else { - my $smtp = Net::SMTP->new($self->session->setting->get("smtpServer")); # connect to an SMTP server + my $smtp = Net::SMTP->new($smtpServer); # connect to an SMTP server if (defined $smtp) { $smtp->mail($mail->head->get("X-Return-Path")); $smtp->to(split(",",$mail->head->get("to"))); @@ -463,7 +473,7 @@ sub send { $smtp->quit; # Close the SMTP connection } else { - $self->session->errorHandler->error("Couldn't connect to mail server: ".$self->session->setting->get("smtpServer")); + $log->error("Couldn't connect to mail server: ".$smtpServer); $status = 0; } } diff --git a/t/Mail/Send.t b/t/Mail/Send.t index 76b90fbf9..1abd1ed9b 100644 --- a/t/Mail/Send.t +++ b/t/Mail/Send.t @@ -165,6 +165,9 @@ SKIP: { $session->config->set( 'emailOverride', $oldEmailOverride ); } +# TODO: Test the emailToLog config setting + + #---------------------------------------------------------------------------- # Cleanup END {