- # Sending mail
- if ( sendmail %mail ) {
- # do something if it works....
- $template->param( SENT => "1" );
+ try {
+
+ my $email = Koha::Email->create(
+ {
+ to => $email_add,
+ subject => $subject,
+ }
+ );
+
+ $email->text_body( $THE_body );
+ $email->attach(
+ Encode::encode( "UTF-8", $iso2709 ),
+ content_type => 'application/octet-stream',
+ name => 'basket.iso2709',
+ disposition => 'attachment',
+ );
+
+ my $library = Koha::Patrons->find( $borrowernumber )->library;
+ $email->send_or_die({ transport => $library->smtp_server->transport });
+ $template->param( SENT => "1" );