package LATMOS::Accounts::Mail; use strict; use warnings; use LATMOS::Accounts::Log; use LATMOS::Accounts; use Mail::Sendmail; use Template; use FindBin qw($Bin); use Sys::Hostname; =head1 NAME LATMOS::Accounts::Mail - Send mail using Template =head1 SYNOPSIS use LATMOS::Accounts::Mail; # Prepare the mail my $mail = LATMOS::Accounts::Mail->new( $la, 'foo.mail', { 'Subject' => 'a mail', } ); # Send it $mail->process({}, { to => 'dest@domain' }); =head1 FUNCTIONS =cut =head2 LATMOS::Accounts::Mail->new($la, $template, $header) Create a new C object. C<$la> is a reference to a C object, C<$template> is the name of the template to use, C<$header> is a hashref containing default mail header to use when sending mail. =cut sub new { my ($class, $la, $template, $headers) = @_; bless { _la => $la, template => $template, headers => $headers, _template => Template->new( INCLUDE_PATH => [ ($la->val('_default_', 'templatespath') ? $la->val('_default_', 'templatespath') . '/mail' : ()), "$FindBin::Bin/../templates" . '/mail', '/usr/share/latmos-accounts/templates/mail', ], POST_CHOMP => 1, EXTENSION => '.mail', ), }, $class; } =head2 $lamail->process($headers, $vars) Process the template as mail body and send the mail. C<$headers> is a hashref to header to use to send the mail (See L. C<$var> is a hashref to be used by L