From bfc85ae99fd4a3e393b85ddee44ef581abf94da1 Mon Sep 17 00:00:00 2001 From: miker Date: Sat, 28 Feb 2009 15:13:14 +0000 Subject: [PATCH] adding a generic SendEmail reactor (already defined by default) that depends on the user-supplied environment and template to work properly git-svn-id: svn://svn.open-ils.org/ILS/trunk@12324 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- .../Application/Trigger/Reactor/SendEmail.pm | 66 ++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendEmail.pm diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendEmail.pm b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendEmail.pm new file mode 100644 index 0000000000..7a52932b25 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Trigger/Reactor/SendEmail.pm @@ -0,0 +1,66 @@ +package OpenILS::Application::Trigger::Reactor::SendEmail; +use Error qw/:try/; +use Data::Dumper; +use Email::Send; +use OpenSRF::Utils::SettingsClient; +use OpenILS::Application::Trigger::Reactor; +use OpenSRF::Utils::Logger qw/:logger/; + +use base 'OpenILS::Application::Trigger::Reactor'; + +my $log = 'OpenSRF::Utils::Logger'; + +sub ABOUT { + return <new; + my $smtp = $conf->config_value('email_notify', 'smtp_server'); + $$env{default_sender} = $conf->config_value('email_notify', 'sender_address'); + + my $text = $self->run_TT($env); + return 0 if (!$text); + + my $sender = Email::Send->new({mailer => 'SMTP'}); + $sender->mailer_args([Host => $smtp]); + + my $stat; + my $err; + + try { + $stat = $sender->send($text); + } catch Error with { + $err = $stat = shift; + $logger->error("SendEmail Reactor: Email failed with error: $err"); + }; + + if( !$err and $stat and $stat->type eq 'success' ) { + $logger->info("SendEmail Reactor: successfully sent email"); + return 1; + } else { + $logger->warn("SendEmail Reactor: unable to send email: ".Dumper($stat)); + return 0; + } + +} + +1; + -- 2.11.0