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

(-)a/C4/Letters.pm (-2 / +13 lines)
Lines 1592-1601 sub _send_message_by_email { Link Here
1592
    return unless $email;
1592
    return unless $email;
1593
1593
1594
    my $smtp_server;
1594
    my $smtp_server;
1595
    if ($library) {
1595
    if ( $library && $from_address eq $branch_email ) {
1596
        $smtp_server = $library->smtp_server;
1596
        $smtp_server = $library->smtp_server;
1597
    } else {
1597
    } else {
1598
        $smtp_server = Koha::SMTP::Servers->get_default;
1598
        my $libs = Koha::Libraries->search( { branchemail => $from_address } );
1599
        while ( my $lib = $libs->next ) {
1600
            my $lib_smtp = $lib->smtp_server;
1601
            if ($lib_smtp) {
1602
                $smtp_server = $lib_smtp;
1603
                last;
1604
            }
1605
        }
1606
1607
        unless ($smtp_server) {
1608
            $smtp_server = Koha::SMTP::Servers->get_default;
1609
        }
1599
    }
1610
    }
1600
1611
1601
    if ($username) {
1612
    if ($username) {
(-)a/t/db_dependent/Letters.t (-2 / +84 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use File::Basename qw(dirname);
21
use File::Basename qw(dirname);
22
use Test::More tests => 105;
22
use Test::More tests => 106;
23
use Test::NoWarnings;
23
use Test::NoWarnings;
24
24
25
use Test::MockModule;
25
use Test::MockModule;
Lines 1825-1828 subtest 'Virtual method ->strftime in notices' => sub { Link Here
1825
    is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' );
1825
    is( $get_letter->()->{content}, $expected_output, 'Check generated content for us dateformat' );
1826
};
1826
};
1827
1827
1828
subtest 'SMTP resolution based on from_address' => sub {
1829
1830
    plan tests => 2;
1831
1832
    my $lib_default = $builder->build_object(
1833
        {
1834
            class => 'Koha::Libraries',
1835
            value => {
1836
                branchcode  => 'DEF',
1837
                branchname  => 'Default Library',
1838
                branchemail => 'default@library.com',
1839
            }
1840
        }
1841
    );
1842
1843
    my $lib_custom = $builder->build_object(
1844
        {
1845
            class => 'Koha::Libraries',
1846
            value => {
1847
                branchcode  => 'CUS',
1848
                branchname  => 'Custom Library',
1849
                branchemail => 'custom@library.com',
1850
            }
1851
        }
1852
    );
1853
1854
    my $smtp_custom = $builder->build_object(
1855
        {
1856
            class => 'Koha::SMTP::Servers',
1857
            value => {
1858
                name => 'Custom SMTP',
1859
                host => 'smtp.custom.test',
1860
            }
1861
        }
1862
    );
1863
    my $smtp_default = $builder->build_object(
1864
        {
1865
            class => 'Koha::SMTP::Servers',
1866
            value => {
1867
                name => 'Default SMTP',
1868
                host => 'smtp.default.test',
1869
            }
1870
        }
1871
    );
1872
1873
    $lib_default->smtp_server( { smtp_server => $smtp_default } );
1874
    $lib_custom->smtp_server( { smtp_server => $smtp_custom } );
1875
1876
    my $used_transport;
1877
    my $mock_stuffer = Test::MockModule->new('Email::Stuffer');
1878
    $mock_stuffer->mock(
1879
        'send_or_die',
1880
        sub {
1881
            my ( $self, $args ) = @_;
1882
            $used_transport = $args->{transport};
1883
            return 1;
1884
        }
1885
    );
1886
1887
    C4::Letters::_send_message_by_email(
1888
        {
1889
            to_address   => 'user@test.com',
1890
            from_address => 'custom@library.com',
1891
            content      => 'Test',
1892
            subject      => 'Test subject',
1893
        }
1894
    );
1895
1896
    is( $used_transport->host, 'smtp.custom.test', 'Uses custom SMTP' );
1897
1898
    C4::Letters::_send_message_by_email(
1899
        {
1900
            to_address   => 'user@test.com',
1901
            from_address => 'default@library.com',
1902
            content      => 'Test',
1903
            subject      => 'Test subject',
1904
        }
1905
    );
1906
1907
    is( $used_transport->host, 'smtp.default.test', 'Uses default SMTP' );
1908
1909
};
1910
1828
$schema->storage->txn_rollback;
1911
$schema->storage->txn_rollback;
1829
- 

Return to bug 41965