View | Details | Raw Unified | Return to bug 22343
Collapse All | Expand All

(-)a/Koha/Illrequest.pm (-15 / +19 lines)
Lines 21-28 use Modern::Perl; Link Here
21
21
22
use Clone 'clone';
22
use Clone 'clone';
23
use File::Basename qw( basename );
23
use File::Basename qw( basename );
24
use Email::Sender::Simple qw(sendmail);
24
use Encode qw( encode );
25
use Encode qw( encode );
25
use Mail::Sendmail;
26
use Try::Tiny;
26
use Try::Tiny;
27
use DateTime;
27
use DateTime;
28
28
Lines 40-45 use Koha::Biblios; Link Here
40
use Koha::Items;
40
use Koha::Items;
41
use Koha::ItemTypes;
41
use Koha::ItemTypes;
42
use Koha::Libraries;
42
use Koha::Libraries;
43
use Koha::SMTP::Server;
44
43
use C4::Circulation qw( CanBookBeIssued AddIssue  );
45
use C4::Circulation qw( CanBookBeIssued AddIssue  );
44
46
45
use base qw(Koha::Object);
47
use base qw(Koha::Object);
Lines 1284-1290 attempts to submit the email. Link Here
1284
1286
1285
sub generic_confirm {
1287
sub generic_confirm {
1286
    my ( $self, $params ) = @_;
1288
    my ( $self, $params ) = @_;
1287
    my $branch = Koha::Libraries->find($params->{current_branchcode})
1289
    my $library = Koha::Libraries->find($params->{current_branchcode})
1288
        || die "Invalid current branchcode. Are you logged in as the database user?";
1290
        || die "Invalid current branchcode. Are you logged in as the database user?";
1289
    if ( !$params->{stage}|| $params->{stage} eq 'init' ) {
1291
    if ( !$params->{stage}|| $params->{stage} eq 'init' ) {
1290
        my $draft->{subject} = "ILL Request";
1292
        my $draft->{subject} = "ILL Request";
Lines 1309-1315 Kind Regards Link Here
1309
1311
1310
EOF
1312
EOF
1311
1313
1312
        my @address = map { $branch->$_ }
1314
        my @address = map { $library->$_ }
1313
            qw/ branchname branchaddress1 branchaddress2 branchaddress3
1315
            qw/ branchname branchaddress1 branchaddress2 branchaddress3
1314
                branchzip branchcity branchstate branchcountry branchphone
1316
                branchzip branchcity branchstate branchcountry branchphone
1315
                branchemail /;
1317
                branchemail /;
Lines 1346-1372 EOF Link Here
1346
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1348
            "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
1347
          if ( !$to );
1349
          if ( !$to );
1348
        # Create the from, replyto and sender headers
1350
        # Create the from, replyto and sender headers
1349
        my $from = $branch->branchemail;
1351
        my $from = $library->branchemail;
1350
        my $replyto = $branch->branchreplyto || $from;
1352
        my $replyto = $library->branchreplyto || $from;
1351
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1353
        Koha::Exceptions::Ill::NoLibraryEmail->throw(
1352
            "Your library has no usable email address. Please set it.")
1354
            "Your library has no usable email address. Please set it.")
1353
          if ( !$from );
1355
          if ( !$from );
1354
1356
1355
        # Create the email
1357
        # Create the email
1356
        my $message = Koha::Email->new;
1358
        my $email = Koha::Email->create(
1357
        my %mail = $message->create_message_headers(
1358
            {
1359
            {
1359
                to          => $to,
1360
                to          => $to,
1360
                from        => $from,
1361
                from        => $from,
1361
                replyto     => $replyto,
1362
                replyto     => $replyto,
1362
                subject     => Encode::encode( "utf8", $params->{subject} ),
1363
                subject     => Encode::encode( "utf8", $params->{subject} ),
1363
                message     => Encode::encode( "utf8", $params->{body} ),
1364
                text_body   => Encode::encode( "utf8", $params->{body} ),
1364
                contenttype => 'text/plain',
1365
            }
1365
            }
1366
        );
1366
        );
1367
1367
        # Send it
1368
        # Send it
1368
        my $result = sendmail(%mail);
1369
        try {
1369
        if ( $result ) {
1370
1371
            my $smtp_server = Koha::SMTP::Servers->get_effective_server({ library => $library });
1372
            Email::Sender::Simple::sendmail( $email, { transport => $smtp_server->transport } );
1373
1370
            $self->status("GENREQ")->store;
1374
            $self->status("GENREQ")->store;
1371
            $self->_backend_capability(
1375
            $self->_backend_capability(
1372
                'set_requested_partners',
1376
                'set_requested_partners',
Lines 1383-1397 EOF Link Here
1383
                stage   => 'commit',
1387
                stage   => 'commit',
1384
                next    => 'illview',
1388
                next    => 'illview',
1385
            };
1389
            };
1386
        } else {
1390
        }
1391
        catch {
1387
            return {
1392
            return {
1388
                error   => 1,
1393
                error   => 1,
1389
                status  => 'email_failed',
1394
                status  => 'email_failed',
1390
                message => $Mail::Sendmail::error,
1395
                message => "$_",
1391
                method  => 'generic_confirm',
1396
                method  => 'generic_confirm',
1392
                stage   => 'draft',
1397
                stage   => 'draft',
1393
            };
1398
            };
1394
        }
1399
        };
1395
    } else {
1400
    } else {
1396
        die "Unknown stage, should not have happened."
1401
        die "Unknown stage, should not have happened."
1397
    }
1402
    }
1398
- 

Return to bug 22343