Bugzilla – Attachment 189906 Details for
Bug 29587
Test mail option in SMTP servers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 29587: Test mail option in SMTP servers
Bug-29587-Test-mail-option-in-SMTP-servers.patch (text/plain), 5.88 KB, created by
Saiful Amin
on 2025-11-24 10:16:08 UTC
(
hide
)
Description:
Bug 29587: Test mail option in SMTP servers
Filename:
MIME Type:
Creator:
Saiful Amin
Created:
2025-11-24 10:16:08 UTC
Size:
5.88 KB
patch
obsolete
>From fb7bc7f0ec002c45d3ce7e622f4075e5e759db0b Mon Sep 17 00:00:00 2001 >From: Saiful Amin <saiful@semanticconsulting.com> >Date: Mon, 24 Nov 2025 09:22:47 +0000 >Subject: [PATCH] Bug 29587: Test mail option in SMTP servers >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >This patch adds a "Send test email" action to the SMTP servers >administration page. It sends a test message to the address in >the KohaAdminEmailAddress system preference and reports success >or failure to the user. > >Test plan: >1. Add a valid SMTP server in Administration รข SMTP servers. >2. Set KohaAdminEmailAddress to a valid email address. >3. Apply the patch. >4. Click "Send test email" in the Actions column. >5. Confirm that Koha reports "Test email sent successfully". >6. Edit the SMTP server and change the domain to an invalid one. >7. Click "Send test email" again. >8. Confirm that Koha reports failure. >9. Sign off. >--- > admin/smtp_servers.pl | 49 +++++++++++++++++++ > .../prog/en/modules/admin/smtp_servers.tt | 9 +++- > 2 files changed, 56 insertions(+), 2 deletions(-) > >diff --git a/admin/smtp_servers.pl b/admin/smtp_servers.pl >index c01290f..0194a87 100755 >--- a/admin/smtp_servers.pl >+++ b/admin/smtp_servers.pl >@@ -107,6 +107,55 @@ if ( $op eq 'cud-add' ) { > reason => 'invalid_id' > }; > } >+} elsif ( $op eq 'test_email' ) { >+ my $smtp_server_id = $input->param('smtp_server_id'); >+ my $smtp_server; >+ >+ $smtp_server = Koha::SMTP::Servers->find($smtp_server_id) >+ unless !$smtp_server_id; >+ >+ if ($smtp_server) { >+ my $test_email_address = C4::Context->preference('KohaAdminEmailAddress'); >+ my $smtp_transport = $smtp_server->transport; >+ >+ my $params = { >+ to => $test_email_address, >+ from => $test_email_address, >+ sender => $test_email_address, >+ subject => "Koha SMTP Test", >+ text_body => "Email is working." >+ }; >+ >+ my $email = Koha::Email->create($params); >+ >+ try { >+ $email->send_or_die( { transport => $smtp_transport } ); >+ push @messages, >+ { >+ type => 'message', >+ code => 'success_on_test' >+ }; >+ } catch { >+ push @messages, >+ { >+ type => 'alert', >+ code => 'error_on_test' >+ }; >+ }; >+ >+ $template->param( >+ servers_count => $smtp_servers->count, >+ default_config => $smtp_servers->get_default, >+ ); >+ >+ } else { >+ push @messages, >+ { >+ type => 'alert', >+ code => 'error_on_test', >+ reason => 'invalid_id' >+ }; >+ } > } elsif ( $op eq 'cud-edit_save' ) { > > my $smtp_server_id = $input->param('smtp_server_id'); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >index 9e6e742..f00fdab 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smtp_servers.tt >@@ -60,10 +60,14 @@ > [% SWITCH m.code %] > [% CASE 'error_on_update' %] > <span>An error occurred trying to open the server for editing. The passed ID is invalid.</span> >+ [% CASE 'error_on_test' %] >+ <span>Failed to send test email.</span> > [% CASE 'error_on_insert' %] > <span>An error occurred when adding the server. The library already has an SMTP server set.</span> > [% CASE 'success_on_update' %] > <span>Server updated successfully.</span> >+ [% CASE 'success_on_test' %] >+ <span>Test email sent successfully to <em>KohaAdminEmailAddress</em>.</span> > [% CASE 'success_on_insert' %] > <span>Server added successfully.</span> > [% CASE %] >@@ -241,7 +245,7 @@ > </form> > [% END %] > >- [% IF op == 'list' %] >+ [% IF op == 'list' || op == 'test_email' %] > <div id="toolbar" class="btn-toolbar"> > <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> > </div> >@@ -421,7 +425,8 @@ > { > "data": function( row, type, val, meta ) { > var result = '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=edit_form&smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa-solid fa-pencil" aria-hidden="true"></i> '+_("Edit")+'</a>'+"\n"; >- 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>'; >+ 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"; >+ result += '<a class="btn btn-default btn-xs" role="button" href="/cgi-bin/koha/admin/smtp_servers.pl?op=test_email&smtp_server_id='+ encodeURIComponent(row.smtp_server_id) +'"><i class="fa fa-check-square" aria-hidden="true"></i> '+_("Send test email")+'</a>'; > return result; > }, > "searchable": false, >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 29587
: 189906