Activator

 view release on metacpan or  search on metacpan

lib/Activator/Emailer.pm  view on Meta::CPAN

package Activator::Emailer;

use strict;
use Email::Send;
use MIME::Lite;
use Template;
use Activator::Registry;
use Exception::Class::TryCatch;
use Data::Dumper;
use Hash::Merge;
use Activator::Log qw( :levels );

=head1 NAME

Activator::Emailer - Send emails from anywhere within a project in the same way using role-based configuration.

=head1 SYNOPSIS

Configure defaults with Activator::Registry configuration (See
L<CONFIGURATION>), then:

  use Activator::Emailer;
  my $tt_vars = { data => 'any data your template needs',
                  other_data => $my_data,
                };
  my $mailer = Activator::Emailer->new(
     To          => 'person@test.com',
     Cc          => 'other@test.com, other2@test.com'
     Subject     => 'Test Subject',
  );
  $mailer->send( $tt_vars );

Reuse the mailer object to send another mail to someone else using a different
body template, plus an attachment:

  $mailer->set_cc( '' );
  $mailer->set_to( 'someone_else@other-domain.com' );
  $mailer->set_html_body( '/path/to/html_body.tt' );
  $tt_vars = $my_alternate_data_hashref;
  $mailer->attach( Type        => 'application/pdf',
                   Path        => 'path/to/doc.pdf',
                   Filename    => 'doc.pdf',
                   Disposition => 'attachment' );
  $mailer->send( $tt_vars );

=head1 DESCRIPTION

C<Activator::Emailer> is a simple wrapper to L<Mime::Lite>,
L<Template::Toolkit> and L<Email::Send> that uses your project's
L<Activator::Registry> to facilitate easy sending of multipart
text/html email from any module in your project. Emailer can talk to
any MTAs that L<Email::Send> can.

=head2 Full Example

  use Activator::Emailer;
  my $tt_vars = { data => $my_data,
                  other_data => 'any data your template needs'
                };
  my $mailer = Activator::Emailer->new(
     From        => 'no-reply@test.com',
     To          => 'person@test.com',
     Cc          => 'other@test.com, other2@test.com'
     Subject     => 'Test Subject',
     html_header => '/path/to/html_header.tt',
     html_body   => '/path/to/html_body.tt',
     html_footer => '/path/to/html_footer.tt',
     email_wrap  => '/path/to/email/wrapper/template',
     mailer_type => 'Gmail',



( run in 0.670 second using v1.01-cache-2.11-cpan-39bf76dae61 )