[Bug 42870] New: Add plugin hook for email transports
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 Bug ID: 42870 Summary: Add plugin hook for email transports Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: Architecture, internals, and plumbing Assignee: koha-bugs@lists.koha-community.org Reporter: dcook@prosentient.com.au QA Contact: testopia@bugs.koha-community.org Target Milestone: --- I'm proposing to add a plugin hook for email transports (e.g. email_transport), so that Koha::SMTP::Server can use a transport supplied by a Koha Plugin rather than Email::Sender::Transport::SMTP::Persistent in Koha::SMTP::Server::transport(). This would enable us to quickly add options for newer SMTP authentication methods (see bug 38338 regarding SMTP XOAUTH2) or to use APIs for sending emails (see bug 42179 for using Microsoft Graph API for sending email). -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=38338, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42179 Assignee|koha-bugs@lists.koha-commun |dcook@prosentient.com.au |ity.org | -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Add plugin hook for email |Make email transports |transports |pluggable -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #1 from David Cook <dcook@prosentient.com.au> --- When I first wrote this (10 minutes ago), I was thinking plugin hook, but... we could actually use Module::Pluggable for this like we do in Koha/SuggestionEngine.pm and Koha/RecordProcess.pm, but taken a step further. Instead of just using a "Koha::<Functionality>" search_path, we can use "Koha::<Functionality>,Koha::Plugin::<Functionality>". We just need to ensure that we have Koha::Plugin::* within our @INC. We can honour existing Koha::Plugin functionality by handling the Koha plugin logic (around installed, enabled, methods, etc) within a helper function within the "hook". But then that being said... it would be up to the plugin author to implement that, and that's messy. Really we could just couple Module::Pluggable "Koha::Email::Transport" AND Koha Plugins with the email_transport hook. Put them in a hash, and then use configuration in the smtp_servers table to choose which one to go with. It does mean a database change, but a very light one... and one which can lead to a lot of possibility -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #2 from David Cook <dcook@prosentient.com.au> --- I could avoid the database change if I just put everything in the plugin, but then that is short-term thinking, because it would be nice to have multiple transports defined in Koha core. So this is a balance of short-term flexibility and innovation while also supporting long-term sustainability. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Small patch Status|NEW |ASSIGNED -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #3 from David Cook <dcook@prosentient.com.au> --- Created attachment 200617 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200617&action=edit Bug 42870: [DO NOT PUSH] DBIC result set changes Patch from commit 721b78b -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #4 from David Cook <dcook@prosentient.com.au> --- Created attachment 200618 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=200618&action=edit Bug 42870: Add email transport config to smtp_servers This change adds a `smtp_servers.config` JSON database column, and adds a "transport_module" method to Koha::STMP::Server, which allow staff users to designate which module they want to use for their email transport for each SMTP Server that they set up. The default transport is the same email transport we've been using for years. The alternatives are supplied by Koha Plugins implementing the new_email_transport() method. These transports have access to the Koha::SMTP::Server object, which also means they can take advantage of this new `smtp_servers.config` field to store additional configuration they might need. This change also comes with a Koha Plugin bundled with it. This plugin is fully operational and just replicates the current "Default" behaviour. It serves as a model from which to build your own Koha Plugins. Test plan: 0. Apply the patch 1. perl /usr/share/koha/bin/devel/install_plugins.pl \ --include Koha::Plugin::Core::Email::Transport::SMTP::Basic 1. restart_all 2. Go to Administration > SMTP servers and click "New SMTP server" 3. Note a new field "Transport module:" which has options of "Default" and "Basic SMTP Email Transport" available in a select list. 4. Fill in the details however you like (ideally using a real functional SMTP server) 5. Click "Submit" 6. Note the "Transport module:" displaying under "Current default configuration" 7. Click on "Edit" next to your SMTP server 8. Change the "Transport module" and click "Submit" 9. Note that the module changes with the modification 10. If possible, try to send an email by going to a patron record (e.g. http://localhost:8081/cgi-bin/koha/members/notices.pl?borrowernumber=51) and clicking "More" and clicking "Send welcome notice" 11. As your Koha instance user (ie using koha-shell), run the following: perl /usr/share/koha/bin/cronjobs/process_message_queue.pl -v 12. If you have a valid SMTP server configured, it should send the email using your selected email transport module -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #5 from David Cook <dcook@prosentient.com.au> --- Note that you can also define an email transport using koha-conf.xml: Just add something like this to your <smtp_server> element: <config>{"transport_module":"Basic SMTP Email Transport"}</config> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42871 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #6 from David Cook <dcook@prosentient.com.au> --- (Oh I also have an idea about trying to localize dependencies within plugins, so that we could do things like take advantage of a newer "Email::Sender::Transport::SMTP::Persistent" for instance to grease the wheels until we can get the newer version at the OS level... keen to try out local @INC...but not today...) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #7 from David Cook <dcook@prosentient.com.au> --- I also need to remember to add the proposed hook to the wiki... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42922, | |https://bugs.koha-community | |.org/bugzilla3/show_bug.cgi | |?id=42923 -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #8 from David Cook <dcook@prosentient.com.au> --- (In reply to David Cook from comment #7)
I also need to remember to add the proposed hook to the wiki...
And added: https://wiki.koha-community.org/wiki/Koha_Plugin_Hooks#Under_development_hoo... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |Needs Signoff --- Comment #9 from David Cook <dcook@prosentient.com.au> --- Thought that I'd marked this as "Needs Signoff" but must've missed it. Too many tabs open sometimes... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |ASSIGNED --- Comment #10 from David Cook <dcook@prosentient.com.au> --- Actually, maybe back to Assigned, since I think this wouldn't pass the QA tools as is. It needs more documentation and possibly a tidy as well. Could do a little unit test as well. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #11 from David Cook <dcook@prosentient.com.au> --- I've submitted a pull request for koha-testing-docker to add a Dovecot container integrated with Keycloak for testing XOAUTH2. Instructions are on the PR: https://gitlab.com/koha-community/koha-testing-docker/-/merge_requests/606 They're based off the work I did testing the C SASL plugin "simple-sasl-xoauth2" https://github.com/minusdavid/simple-sasl-xoauth2/wiki#dovecot-smtp-submissi... -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #200617|0 |1 is obsolete| | Attachment #200618|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #12 from David Cook <dcook@prosentient.com.au> --- Created attachment 201198 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201198&action=edit Bug 42870: [DO NOT PUSH] DBIC result set changes Patch from commit 81ed90c -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #13 from David Cook <dcook@prosentient.com.au> --- Created attachment 201199 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201199&action=edit Bug 42870: Add email transport config to smtp_servers This change adds a `smtp_servers.config` JSON database column, and adds a "transport_module" method to Koha::STMP::Server, which allow staff users to designate which module they want to use for their email transport for each SMTP Server that they set up. The default transport is the same email transport we've been using for years. The alternatives are supplied by Koha Plugins implementing the new_email_transport() method. These transports have access to the Koha::SMTP::Server object, which also means they can take advantage of this new `smtp_servers.config` field to store additional configuration they might need. This change also comes with a Koha Plugin bundled with it. This plugin is fully operational and just replicates the current "Default" behaviour. It serves as a model from which to build your own Koha Plugins. Test plan: 0. Apply the patch and run "sudo koha-upgrade-schema kohadev" 1. perl /usr/share/koha/bin/devel/install_plugins.pl \ --include Koha::Plugin::Core::Email::Transport::SMTP::Basic 1. restart_all 2. Go to Administration > SMTP servers and click "New SMTP server" 3. Note a new field "Transport module:" which has options of "Default" and "Basic SMTP Email Transport" available in a select list. 4. Fill in the details however you like (ideally using a real functional SMTP server) 5. Click "Submit" 6. Note the "Transport module:" displaying under "Current default configuration" 7. Click on "Edit" next to your SMTP server 8. Change the "Transport module" and click "Submit" 9. Note that the module changes with the modification 10. If possible, try to send an email by going to a patron record (e.g. http://localhost:8081/cgi-bin/koha/members/notices.pl?borrowernumber=51) and clicking "More" and clicking "Send welcome notice" 11. As your Koha instance user (ie using koha-shell), run the following: perl /usr/share/koha/bin/cronjobs/process_message_queue.pl -v 12. If you have a valid SMTP server configured, it should send the email using your selected email transport module -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #14 from David Cook <dcook@prosentient.com.au> --- I've added some documentation, made some tweaks, and added a WIP XOAUTH2 plugin. I'd like to cache the access token, use encryption for secrets in smtp_servers.config, add support for the refresh_token grant, and create an interactive plugin page that lets you use the authorization code grant to get an access token and refresh token - if you're not able to use client credential grants (like with Google). -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #15 from David Cook <dcook@prosentient.com.au> --- I am thinking maybe it is best if I move the plugins out of this patch set as it's adding more complication than is neccessary for this change. I can do that tonight or tomorrow night I think. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 David Cook <dcook@prosentient.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |In Discussion -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42870 --- Comment #16 from David Cook <dcook@prosentient.com.au> --- Btw if people want an even simpler version of this, I'll take out the 2 embedded plugins. No problem. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org