App-Framework
view release on metacpan or search on metacpan
lib/App/Framework/Feature/Mail.pm view on Meta::CPAN
=item B<error_to> - Error mail recipient(s)
Email recipient for errors. If set, program errors are sent to this email.
=item B<err_level> - Error level for mails
Set the minium error level that triggers an email. Level can be: note, warning, error
=item B<subject> - Mail subject
Optional mail subject line
=item B<host> - Mail host
Mailing host. If not specified uses 'localhost'
=back
=cut
my %FIELDS = (
'from' => '',
'to' => '',
'error_to' => '',
'err_level' => 'error',
'subject' => '',
'host' => 'localhost',
## Private
'_caught_error' => 0,
) ;
#============================================================================================
=head2 CONSTRUCTOR
=over 4
=cut
#============================================================================================
=item B< new([%args]) >
Create a new Mail.
The %args are specified as they would be in the B<set> method (see L</Fields>).
=cut
sub new
{
my ($obj, %args) = @_ ;
my $class = ref($obj) || $obj ;
# Create object
my $this = $class->SUPER::new(%args,
'requires' => [qw/Net::SMTP/],
'registered' => [qw/application_entry catch_error_entry/],
'feature_options' => \@OPTIONS,
) ;
## If associated with an app, set options
my $app = $this->app ;
if ($app)
{
## Set options
$app->feature('Options')->append_options(\@OPTIONS) ;
## Update option defaults
$app->feature('Options')->defaults_from_obj($this, [keys %FIELDS]) ;
}
return($this) ;
}
#============================================================================================
=back
=head2 CLASS METHODS
=over 4
=cut
#============================================================================================
#-----------------------------------------------------------------------------
=item B< init_class([%args]) >
Initialises the Mail object class variables.
=cut
sub init_class
{
my $class = shift ;
my (%args) = @_ ;
# Add extra fields
$class->add_fields(\%FIELDS, \%args) ;
# init class
$class->SUPER::init_class(%args) ;
}
#============================================================================================
=back
=head2 OBJECT METHODS
=over 4
=cut
#============================================================================================
#--------------------------------------------------------------------------------------------
=item B< mail($content [, %args]) >
Send some mail stored in $content. $content may either be a string (containing newlines), or an
ARRAY ref.
Optionally %args may be specified (to set 'subject' etc).
If no arguments are specified then just returns the mail object.
=cut
sub mail
{
my $this = shift ;
my ($content, %args) = @_ ;
return $this unless $content ;
$this->_dbg_prt(["mail() : content=\"$content\"\n"]) ;
$this->set(%args) ;
my $from = $this->from ;
my $mail_to = $this->to ;
my $subject = $this->subject ;
my $host = $this->host ;
## error check
$this->throw_fatal("Mail: not specified 'from' field") unless $from ;
$this->throw_fatal("Mail: not specified 'to' field") unless $mail_to ;
$this->throw_fatal("Mail: not specified 'host' field") unless $host ;
my @content ;
if (ref($content) eq 'ARRAY')
{
@content = @$content ;
}
elsif (!ref($content))
{
@content = split /\n/, $content ;
}
( run in 1.203 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )