From a9708d50b72dce8821599c1208a22c83fb85857a Mon Sep 17 00:00:00 2001 From: Didier Gautheron Date: Fri, 24 Sep 2021 14:07:45 +0200 Subject: [PATCH] Bug 28996: Catch error in mail creation --- C4/Letters.pm | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 87b82624c6..cd438ef548 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -324,24 +324,24 @@ sub SendAlerts { ) or return; # FIXME: This 'default' behaviour should be moved to Koha::Email - my $mail = Koha::Email->create( - { - to => $email, - from => $library->branchemail, - reply_to => $library->branchreplyto, - sender => $library->branchreturnpath, - subject => "" . $letter->{title}, - } - ); + my $success = try { + my $mail = Koha::Email->create( + { + to => $email, + from => $library->branchemail, + reply_to => $library->branchreplyto, + sender => $library->branchreturnpath, + subject => "" . $letter->{title}, + } + ); - if ( $letter->{is_html} ) { - $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); - } - else { - $mail->text_body( $letter->{content} ); - } + if ( $letter->{is_html} ) { + $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); + } + else { + $mail->text_body( $letter->{content} ); + } - my $success = try { $mail->send_or_die({ transport => $library->smtp_server->transport }); } catch { @@ -475,33 +475,33 @@ sub SendAlerts { # ... then send mail my $library = Koha::Libraries->find( $userenv->{branch} ); - my $mail = Koha::Email->create( - { - to => join( ',', @email ), - cc => join( ',', @cc ), - ( + my $success = try { + my $mail = Koha::Email->create( + { + to => join( ',', @email ), + cc => join( ',', @cc ), ( - C4::Context->preference("ClaimsBccCopy") - && ( $type eq 'claimacquisition' - || $type eq 'claimissues' ) - ) - ? ( bcc => $userenv->{emailaddress} ) - : () - ), - from => $library->branchemail - || C4::Context->preference('KohaAdminEmailAddress'), - subject => "" . $letter->{title}, - } - ); + ( + C4::Context->preference("ClaimsBccCopy") + && ( $type eq 'claimacquisition' + || $type eq 'claimissues' ) + ) + ? ( bcc => $userenv->{emailaddress} ) + : () + ), + from => $library->branchemail + || C4::Context->preference('KohaAdminEmailAddress'), + subject => "" . $letter->{title}, + } + ); - if ( $letter->{is_html} ) { - $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); - } - else { - $mail->text_body( "" . $letter->{content} ); - } + if ( $letter->{is_html} ) { + $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) ); + } + else { + $mail->text_body( "" . $letter->{content} ); + } - my $success = try { $mail->send_or_die({ transport => $library->smtp_server->transport }); } catch { -- 2.20.1