From 12ee43f67181229a5ae92aa46247f06fbc1c9f0d Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Mon, 4 Aug 2014 11:42:44 +0200 Subject: [PATCH] MT#8395 replace email plugin --- debian/control | 1 + lib/NGCP/Panel.pm | 2 - lib/NGCP/Panel/Controller/EmailTemplate.pm | 11 +++--- lib/NGCP/Panel/Utils/Email.pm | 43 ++++++++++++++++------ 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/debian/control b/debian/control index 489108aa70..c7536a1a2e 100644 --- a/debian/control +++ b/debian/control @@ -24,6 +24,7 @@ Build-Depends: debhelper (>= 8), libdevel-cover-perl, libemail-mime-perl, libemail-sender-perl, + libemail-valid-perl, libfile-spec-perl (>= 3.4000~), libfile-type-perl, libgd-gd2-perl, diff --git a/lib/NGCP/Panel.pm b/lib/NGCP/Panel.pm index 34be829d9a..25e8ce6462 100644 --- a/lib/NGCP/Panel.pm +++ b/lib/NGCP/Panel.pm @@ -172,8 +172,6 @@ __PACKAGE__->config( ); __PACKAGE__->config( default_view => 'HTML' ); -__PACKAGE__->config( email => ['Sendmail'] ); - __PACKAGE__->log(Log::Log4perl::Catalyst->new($logger_config)); # Start the application diff --git a/lib/NGCP/Panel/Controller/EmailTemplate.pm b/lib/NGCP/Panel/Controller/EmailTemplate.pm index 67f9433614..82256af8ad 100644 --- a/lib/NGCP/Panel/Controller/EmailTemplate.pm +++ b/lib/NGCP/Panel/Controller/EmailTemplate.pm @@ -5,6 +5,7 @@ BEGIN { extends 'Catalyst::Controller'; } use NGCP::Panel::Form::EmailTemplate::Reseller; use NGCP::Panel::Form::EmailTemplate::Admin; +use NGCP::Panel::Utils::Email; use NGCP::Panel::Utils::Message; sub auto :Does(ACL) :ACLDetachTo('/denied_page') :AllowedRole(admin) :AllowedRole(reseller) { @@ -244,12 +245,10 @@ sub send_test :Chained('tmpl_list') :PathPart('test') :Args(0) { $c->forward($c->view('TT')); my $body = $c->res->body; $c->res->body(undef); - $c->email( - header => [ - From => 'noreply@yoursipserver.com', - To => 'agranig@sipwise.com', - Subject => 'test from catalyst ' . time, - ], + NGCP::Panel::Utils::Email::send_email( + from => 'noreply@yoursipserver.com', + to => 'agranig@sipwise.com', + subject => 'test from catalyst ' . time, body => $body, ); diff --git a/lib/NGCP/Panel/Utils/Email.pm b/lib/NGCP/Panel/Utils/Email.pm index d3377430ae..716ec834af 100644 --- a/lib/NGCP/Panel/Utils/Email.pm +++ b/lib/NGCP/Panel/Utils/Email.pm @@ -2,6 +2,29 @@ package NGCP::Panel::Utils::Email; use Sipwise::Base; use Template; +use Email::Sender::Simple qw(); +use Email::Simple; +use Email::Simple::Creator; +use Email::Sender::Transport::Sendmail qw(); + +sub send_email { + my %args = @_; + my $subject = $args{subject}; + my $body = $args{body}; + my $from = $args{from}; + my $to = $args{to}; + + my $transport = Email::Sender::Transport::Sendmail->new; + my $email = Email::Simple->create( + header => [ + To => $to, + From => $from, + Subject => $subject, + ], + body => $body, + ); + return Email::Sender::Simple->send($email, { transport => $transport } ); +} sub send_template { my ($c, $vars, $subject, $body, $from, $to) = @_; @@ -15,13 +38,11 @@ sub send_template { $t->process(\$subject, $vars, \$processed_subject) || die "error processing email template, type=".$t->error->type.", info='".$t->error->info."'"; - $c->email( - header => [ - From => $from, - To => $to, - Subject => $processed_subject, - ], + send_email( + subject => $processed_subject, body => $processed_body, + from => $from, + to => $to, ); #my $template_processed = process_template({ # subject => $subject, @@ -30,13 +51,11 @@ sub send_template { # to => $to, #},$vars); # - #$c->email( - # header => [ - # From => $template_processed->{from_email}, - # To => $template_processed->{to}, - # Subject => $template_processed->{subject}, - # ], + #send_email( + # subject => $template_processed->{subject}, # body => $template_processed->{body}, + # from => $template_processed->{from_email}, + # to => $template_processed->{to}, #); return 1;