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

(-)a/admin/smtp_servers.pl (+49 lines)
Lines 107-112 if ( $op eq 'cud-add' ) { Link Here
107
            reason => 'invalid_id'
107
            reason => 'invalid_id'
108
            };
108
            };
109
    }
109
    }
110
} elsif ( $op eq 'test_email' ) {
111
    my $smtp_server_id = $input->param('smtp_server_id');
112
    my $smtp_server;
113
114
    $smtp_server = Koha::SMTP::Servers->find($smtp_server_id)
115
        unless !$smtp_server_id;
116
117
    if ($smtp_server) {
118
        my $test_email_address = C4::Context->preference('KohaAdminEmailAddress');
119
        my $smtp_transport     = $smtp_server->transport;
120
121
        my $params = {
122
            to        => $test_email_address,
123
            from      => $test_email_address,
124
            sender    => $test_email_address,
125
            subject   => "Koha SMTP Test",
126
            text_body => "Email is working."
127
        };
128
129
        my $email = Koha::Email->create($params);
130
131
        try {
132
            $email->send_or_die( { transport => $smtp_transport } );
133
            push @messages,
134
                {
135
                type => 'message',
136
                code => 'success_on_test'
137
                };
138
        } catch {
139
            push @messages,
140
                {
141
                type   => 'alert',
142
                code   => 'error_on_test'
143
                };
144
        };
145
146
        $template->param(
147
            servers_count  => $smtp_servers->count,
148
            default_config => $smtp_servers->get_default,
149
        );
150
151
    } else {
152
        push @messages,
153
            {
154
            type   => 'alert',
155
            code   => 'error_on_test',
156
            reason => 'invalid_id'
157
            };
158
    }
110
} elsif ( $op eq 'cud-edit_save' ) {
159
} elsif ( $op eq 'cud-edit_save' ) {
111
160
112
    my $smtp_server_id = $input->param('smtp_server_id');
161
    my $smtp_server_id = $input->param('smtp_server_id');
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt (-3 / +7 lines)
Lines 60-69 Link Here
60
            [% SWITCH m.code %]
60
            [% SWITCH m.code %]
61
            [% CASE 'error_on_update' %]
61
            [% CASE 'error_on_update' %]
62
                <span>An error occurred trying to open the server for editing. The passed ID is invalid.</span>
62
                <span>An error occurred trying to open the server for editing. The passed ID is invalid.</span>
63
            [% CASE 'error_on_test' %]
64
                <span>Failed to send test email.</span>
63
            [% CASE 'error_on_insert' %]
65
            [% CASE 'error_on_insert' %]
64
                <span>An error occurred when adding the server. The library already has an SMTP server set.</span>
66
                <span>An error occurred when adding the server. The library already has an SMTP server set.</span>
65
            [% CASE 'success_on_update' %]
67
            [% CASE 'success_on_update' %]
66
                <span>Server updated successfully.</span>
68
                <span>Server updated successfully.</span>
69
            [% CASE 'success_on_test' %]
70
                <span>Test email sent successfully to <em>KohaAdminEmailAddress</em>.</span>
67
            [% CASE 'success_on_insert' %]
71
            [% CASE 'success_on_insert' %]
68
                <span>Server added successfully.</span>
72
                <span>Server added successfully.</span>
69
            [% CASE %]
73
            [% CASE %]
Lines 241-247 Link Here
241
        </form>
245
        </form>
242
    [% END %]
246
    [% END %]
243
247
244
    [% IF op == 'list' %]
248
    [% IF op == 'list' || op == 'test_email' %]
245
        <div id="toolbar" class="btn-toolbar">
249
        <div id="toolbar" class="btn-toolbar">
246
            <a class="btn btn-default" id="new_smtp_server" href="/cgi-bin/koha/admin/smtp_servers.pl?op=add_form"><i class="fa fa-plus"></i> New SMTP server</a>
250
            <a class="btn btn-default" id="new_smtp_server" href="/cgi-bin/koha/admin/smtp_servers.pl?op=add_form"><i class="fa fa-plus"></i> New SMTP server</a>
247
        </div>
251
        </div>
Lines 421-427 Link Here
421
                    {
425
                    {
422
                        "data": function( row, type, val, meta ) {
426
                        "data": function( row, type, val, meta ) {
423
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa-solid fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
427
                            var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa-solid fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n";
424
                            result += '<a class="btn btn-default btn-xs delete_server" role="button" href="#" data-bs-toggle="modal" data-bs-target="#delete_confirm_modal" data-smtp-server-id="'+ encodeURIComponent(row.smtp_server_id) +'" data-smtp-server-name="'+ encodeURIComponent(row.name.escapeHtml()) +'"><i class="fa fa-trash-can" aria-hidden="true"></i> '+_("Delete")+'</a>';
428
                            result += '<a class="btn btn-default btn-xs delete_server" role="button" href="#" data-bs-toggle="modal" data-bs-target="#delete_confirm_modal" data-smtp-server-id="'+ encodeURIComponent(row.smtp_server_id) +'" data-smtp-server-name="'+ encodeURIComponent(row.name.escapeHtml()) +'"><i class="fa fa-trash-can" aria-hidden="true"></i> '+_("Delete")+'</a>'+"\n";
429
                            result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=test_email&amp;smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-check-square" aria-hidden="true"></i> '+_("Send test email")+'</a>';
425
                            return result;
430
                            return result;
426
                        },
431
                        },
427
                        "searchable": false,
432
                        "searchable": false,
428
- 

Return to bug 29587