1 package OpenILS::Application::Trigger::Reactor::SendEmail;
2 use strict; use warnings;
6 use OpenSRF::Utils::SettingsClient;
7 use OpenILS::Application::Trigger::Reactor;
8 use OpenSRF::Utils::Logger qw/:logger/;
10 $Data::Dumper::Indent = 0;
12 use base 'OpenILS::Application::Trigger::Reactor';
14 my $log = 'OpenSRF::Utils::Logger';
19 The SendEmail Reactor Module attempts to email out, via Email::Send,
20 whatever is constructed by the template passed in from the Event Definition.
22 The SMTP server specified by the /opensrf/default/email_notify/smtp_server
23 setting is used to send the email, and the value at
24 /opensrf/default/email_notify/sender_address is passed into the template as
25 the 'default_sender' variable.
27 No default template is assumed, and all information other than the
28 default_sender that the system provides is expected to be gathered by the
29 Event Definition through either Environment or Parameter definitions.
38 my $conf = OpenSRF::Utils::SettingsClient->new;
39 my $smtp = $conf->config_value('email_notify', 'smtp_server');
40 $$env{default_sender} = $conf->config_value('email_notify', 'sender_address');
42 my $text = $self->run_TT($env);
45 my $sender = Email::Send->new({mailer => 'SMTP'});
46 $sender->mailer_args([Host => $smtp]);
51 utf8::encode($text); # prevent "Wide character" errors in Email::Send
54 $stat = $sender->send($text);
57 $logger->error("SendEmail Reactor: Email failed with error: $err");
60 if( !$err and $stat and $stat->type eq 'success' ) {
61 $logger->info("SendEmail Reactor: successfully sent email");
64 $logger->warn("SendEmail Reactor: unable to send email: ".Dumper($stat));
66 $logger->warn("SendEmail Reactor: failed email template: $text");