Added a config setting that allows email to be piped to the log rather than pass through a mailserver that may or may not exist. Added a TODO test block.
This commit is contained in:
parent
4e7130bee0
commit
7901eb9642
3 changed files with 28 additions and 10 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,6 +165,9 @@ SKIP: {
|
|||
$session->config->set( 'emailOverride', $oldEmailOverride );
|
||||
}
|
||||
|
||||
# TODO: Test the emailToLog config setting
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue