Apache2-WebApp-Plugin-Mail
view release on metacpan or search on metacpan
lib/Apache2/WebApp/Plugin/Mail.pm view on Meta::CPAN
#
#----------------------------------------------------------------------------+
package Apache2::WebApp::Plugin::Mail;
use strict;
use base 'Apache2::WebApp::Plugin';
use MIME::Lite::TT;
use MIME::Lite::TT::HTML;
use Params::Validate qw( :all );
our $VERSION = 0.09;
#~~~~~~~~~~~~~~~~~~~~~~~~~~~[ OBJECT METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#----------------------------------------------------------------------------+
# send_text( \%controller, \%data )
#
# Send a template based (text) message.
sub send_text {
my ( $self, $c, $data_ref )
= validate_pos( @_,
{ type => OBJECT },
{ type => HASHREF },
{ type => HASHREF }
);
my $msg = MIME::Lite::TT->new(
From => $data_ref->{from} || $c->config->{project_email},
To => $data_ref->{to},
Subject => $data_ref->{subject},
Template => $data_ref->{template}->{file},
TmplParams => $data_ref->{template}->{vars},
TmplOptions => {
INCLUDE_PATH => $c->config->{template_include_path}
},
);
$msg->send();
}
#----------------------------------------------------------------------------+
# send_html( \%controller, \%data )
#
# Send a template based (HTML/Text) multi-formatted message.
sub send_html {
my ( $self, $c, $data_ref )
= validate_pos( @_,
{ type => OBJECT },
{ type => HASHREF },
{ type => HASHREF }
);
my $msg = MIME::Lite::TT::HTML->new(
From => $data_ref->{from} || $c->config->{project_email},
To => $data_ref->{to},
Subject => $data_ref->{subject},
Encoding => 'quoted-printable',
Charset => 'utf8',
Template => {
html => $data_ref->{template}->{file}->{html},
text => $data_ref->{template}->{file}->{txt},
},
TmplParams => $data_ref->{template}->{vars},
TmplOptions => {
INCLUDE_PATH => $c->config->{template_include_path}
},
);
$msg->send;
}
#~~~~~~~~~~~~~~~~~~~~~~~~~~[ PRIVATE METHODS ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#----------------------------------------------------------------------------+
# _init(\%params)
#
# Return a reference of $self to the caller.
sub _init {
my ( $self, $params ) = @_;
return $self;
}
1;
__END__
=head1 NAME
Apache2::WebApp::Plugin::Mail - Plugin providing mail delivery methods
=head1 SYNOPSIS
my $obj = $c->plugin('Mail')->method( ... ); # Apache2::WebApp::Plugin::Mail->method()
or
$c->plugin('Mail')->method( ... );
=head1 DESCRIPTION
Methods for sending template based multi-format e-mail.
=head1 PREREQUISITES
This package is part of a larger distribution and was NOT intended to be used
directly. In order for this plugin to work properly, the following packages
must be installed:
Apache2::WebApp
MIME::Lite
MIME::Lite::TT
MIME::Lite::TT::HTML
Params::Validate
=head1 INSTALLATION
From source:
( run in 0.653 second using v1.01-cache-2.11-cpan-39bf76dae61 )