1 package OpenILS::Application::Trigger::Reactor::StaticEmail;
2 use strict; use warnings;
6 use OpenSRF::Utils::SettingsClient;
7 use OpenILS::Application::Trigger::Reactor;
8 use OpenSRF::Utils::Logger qw/:logger/;
10 use base 'OpenILS::Application::Trigger::Reactor';
12 my $log = 'OpenSRF::Utils::Logger';
14 my $default_template = <<TT;
15 To: [%- params.recipient %]
16 From: [%- params.sender %]
17 Subject: [%- params.subject %]
25 The StagicEmail Reactor Module sends an email to the address specified by the
26 "recipient" parameter. This is the only required parameter (in fact the
27 template is not even required), though sender, subject and body parameters are
28 also accepted and used by the default template.
30 The default template looks like:
42 my $conf = OpenSRF::Utils::SettingsClient->new;
43 my $smtp = $conf->config_value('email_notify', 'smtp_server');
44 $$env{params}{sender} ||= $conf->config_value('email_notify', 'sender_address');
45 $$env{params}{subject} ||= 'Test subject -- StaticEmail Reactor';
46 $$env{params}{body} ||= 'Test body -- StaticEmail Reactor';
47 $$env{template} ||= $default_template;
49 $$env{params}{recipient} or return 0;
51 my $text = $self->run_TT($env);
54 $logger->info("StaticEmail Reactor: sending email to ".
55 $$env{params}{recipient}." via SMTP server $smtp");
57 my $sender = Email::Send->new({mailer => 'SMTP'});
58 $sender->mailer_args([Host => $smtp]);
65 $stat = $sender->send($text);
68 $logger->error("StaticEmail Reactor: Email failed with error: $err");
71 if( !$err and $stat and $stat->type eq 'success' ) {
72 $logger->info("StaticEmail Reactor: successfully sent email");
75 $logger->warn("StaticEmail Reactor: unable to send email: ".Dumper($stat));