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

(-)a/C4/Letters.pm (-84 / +83 lines)
Lines 324-347 sub SendAlerts { Link Here
324
            ) or return;
324
            ) or return;
325
325
326
            # FIXME: This 'default' behaviour should be moved to Koha::Email
326
            # FIXME: This 'default' behaviour should be moved to Koha::Email
327
            my $mail = Koha::Email->create(
327
            my $success = try {
328
                {
328
                my $mail = Koha::Email->create(
329
                    to       => $email,
329
                    {
330
                    from     => $library->branchemail,
330
                        to       => $email,
331
                    reply_to => $library->branchreplyto,
331
                        from     => $library->branchemail,
332
                    sender   => $library->branchreturnpath,
332
                        reply_to => $library->branchreplyto,
333
                    subject  => "" . $letter->{title},
333
                        sender   => $library->branchreturnpath,
334
                }
334
                        subject  => "" . $letter->{title},
335
            );
335
                    }
336
                );
336
337
337
            if ( $letter->{is_html} ) {
338
                if ( $letter->{is_html} ) {
338
                $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
339
                    $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
339
            }
340
                }
340
            else {
341
                else {
341
                $mail->text_body( $letter->{content} );
342
                    $mail->text_body( $letter->{content} );
342
            }
343
                }
343
344
344
            my $success = try {
345
                $mail->send_or_die({ transport => $library->smtp_server->transport });
345
                $mail->send_or_die({ transport => $library->smtp_server->transport });
346
            }
346
            }
347
            catch {
347
            catch {
Lines 475-507 sub SendAlerts { Link Here
475
475
476
        # ... then send mail
476
        # ... then send mail
477
        my $library = Koha::Libraries->find( $userenv->{branch} );
477
        my $library = Koha::Libraries->find( $userenv->{branch} );
478
        my $mail = Koha::Email->create(
478
        my $success = try {
479
            {
479
            my $mail = Koha::Email->create(
480
                to => join( ',', @email ),
480
                {
481
                cc => join( ',', @cc ),
481
                    to => join( ',', @email ),
482
                (
482
                    cc => join( ',', @cc ),
483
                    (
483
                    (
484
                        C4::Context->preference("ClaimsBccCopy")
484
                        (
485
                          && ( $type eq 'claimacquisition'
485
                            C4::Context->preference("ClaimsBccCopy")
486
                            || $type eq 'claimissues' )
486
                              && ( $type eq 'claimacquisition'
487
                    )
487
                                || $type eq 'claimissues' )
488
                    ? ( bcc => $userenv->{emailaddress} )
488
                        )
489
                    : ()
489
                        ? ( bcc => $userenv->{emailaddress} )
490
                ),
490
                        : ()
491
                from => $library->branchemail
491
                    ),
492
                  || C4::Context->preference('KohaAdminEmailAddress'),
492
                    from => $library->branchemail
493
                subject => "" . $letter->{title},
493
                      || C4::Context->preference('KohaAdminEmailAddress'),
494
            }
494
                    subject => "" . $letter->{title},
495
        );
495
                }
496
            );
496
497
497
        if ( $letter->{is_html} ) {
498
            if ( $letter->{is_html} ) {
498
            $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
499
                $mail->html_body( _wrap_html( $letter->{content}, "" . $letter->{title} ) );
499
        }
500
            }
500
        else {
501
            else {
501
            $mail->text_body( "" . $letter->{content} );
502
                $mail->text_body( "" . $letter->{content} );
502
        }
503
            }
503
504
504
        my $success = try {
505
            $mail->send_or_die({ transport => $library->smtp_server->transport });
505
            $mail->send_or_die({ transport => $library->smtp_server->transport });
506
        }
506
        }
507
        catch {
507
        catch {
Lines 1389-1442 sub _send_message_by_email { Link Here
1389
        );
1389
        );
1390
        return;
1390
        return;
1391
    };
1391
    };
1392
    my $email = Koha::Email->create(
1392
    try {
1393
        {
1393
        my $email = Koha::Email->create(
1394
            to => $to_address,
1395
            (
1396
                C4::Context->preference('NoticeBcc')
1397
                ? ( bcc => C4::Context->preference('NoticeBcc') )
1398
                : ()
1399
            ),
1400
            from     => $from_address,
1401
            reply_to => $message->{'reply_address'} || $branch_replyto,
1402
            sender   => $branch_returnpath,
1403
            subject  => "" . $message->{subject}
1404
        }
1405
    );
1406
1407
    if ( $is_html ) {
1408
        $email->html_body(
1409
            _wrap_html( $content, $subject )
1410
        );
1411
    }
1412
    else {
1413
        $email->text_body( $content );
1414
    }
1415
1416
    my $smtp_server;
1417
    if ( $library ) {
1418
        $smtp_server = $library->smtp_server;
1419
    }
1420
    else {
1421
        $smtp_server = Koha::SMTP::Servers->get_default;
1422
    }
1423
1424
    if ( $username ) {
1425
        $smtp_server->set(
1426
            {
1394
            {
1427
                sasl_username => $username,
1395
                to => $to_address,
1428
                sasl_password => $password,
1396
                (
1397
                    C4::Context->preference('NoticeBcc')
1398
                    ? ( bcc => C4::Context->preference('NoticeBcc') )
1399
                    : ()
1400
                ),
1401
                from     => $from_address,
1402
                reply_to => $message->{'reply_address'} || $branch_replyto,
1403
                sender   => $branch_returnpath,
1404
                subject  => "" . $message->{subject}
1429
            }
1405
            }
1430
        );
1406
        );
1431
    }
1432
1407
1433
# if initial message address was empty, coming here means that a to address was found and
1408
        if ( $is_html ) {
1434
# queue should be updated; same if to address was overriden by Koha::Email->create
1409
            $email->html_body(
1435
    _update_message_to_address( $message->{'message_id'}, $email->email->header('To') )
1410
                _wrap_html( $content, $subject )
1436
      if !$message->{to_address}
1411
            );
1437
      || $message->{to_address} ne $email->email->header('To');
1412
        }
1413
        else {
1414
            $email->text_body( $content );
1415
        }
1416
1417
        my $smtp_server;
1418
        if ( $library ) {
1419
            $smtp_server = $library->smtp_server;
1420
        }
1421
        else {
1422
            $smtp_server = Koha::SMTP::Servers->get_default;
1423
        }
1424
1425
        if ( $username ) {
1426
            $smtp_server->set(
1427
                {
1428
                    sasl_username => $username,
1429
                    sasl_password => $password,
1430
                }
1431
            );
1432
        }
1433
1434
        # if initial message address was empty, coming here means that a to address was found and
1435
        # queue should be updated; same if to address was overriden by Koha::Email->create
1436
        _update_message_to_address( $message->{'message_id'}, $email->email->header('To') )
1437
        if !$message->{to_address}
1438
            || $message->{to_address} ne $email->email->header('To');
1438
1439
1439
    try {
1440
        $email->send_or_die({ transport => $smtp_server->transport });
1440
        $email->send_or_die({ transport => $smtp_server->transport });
1441
1441
1442
        _set_message_status(
1442
        _set_message_status(
1443
- 

Return to bug 28996