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