Merge pull request #1302 from garnier-quentin/bug-smtp-error

+ Fix smtp bug (#1172)
This commit is contained in:
qgarnier 2019-01-01 15:26:59 +01:00 committed by GitHub
commit 36c3b57a38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -95,14 +95,14 @@ sub connect {
$smtp_options{-$1} = $2; $smtp_options{-$1} = $2;
} }
my ($stdout); my ($stdout, $error_msg);
{ {
eval { eval {
local $SIG{ALRM} = sub { die 'timeout' }; local $SIG{ALRM} = sub { die 'timeout' };
local *STDOUT; local *STDOUT;
open STDOUT, '>', \$stdout; open STDOUT, '>', \$stdout;
alarm($self->{option_results}->{timeout}); alarm($self->{option_results}->{timeout});
$smtp_handle = Email::Send::SMTP::Gmail->new(-smtp=> $self->{option_results}->{hostname}, ($smtp_handle, $error_msg) = Email::Send::SMTP::Gmail->new(-smtp=> $self->{option_results}->{hostname},
%smtp_options); %smtp_options);
alarm(0); alarm(0);
}; };
@ -114,10 +114,10 @@ sub connect {
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }
if (defined($stdout) && $smtp_handle == -1) { if ($smtp_handle == -1) {
chomp $stdout; chomp $stdout;
$self->{output}->output_add(severity => $connection_exit, $self->{output}->output_add(severity => $connection_exit,
short_msg => 'Unable to connect to SMTP: ' . $stdout); short_msg => 'Unable to connect to SMTP: ' . (defined($stdout) ? $stdout : $error_msg));
$self->{output}->display(); $self->{output}->display();
$self->{output}->exit(); $self->{output}->exit();
} }