1package Log::Dispatch::Email::MailSender; 2{ 3 $Log::Dispatch::Email::MailSender::VERSION = '2.34'; 4} 5 6# By: Joseph Annino 7# (c) 2002 8# Licensed under the same terms as Perl 9# 10 11use strict; 12use warnings; 13 14use Log::Dispatch::Email; 15 16use base qw( Log::Dispatch::Email ); 17 18use Mail::Sender (); 19 20sub new { 21 my $proto = shift; 22 my $class = ref $proto || $proto; 23 24 my %p = @_; 25 26 my $smtp = delete $p{smtp} || 'localhost'; 27 28 my $self = $class->SUPER::new(%p); 29 30 $self->{smtp} = $smtp; 31 32 return $self; 33} 34 35sub send_email { 36 my $self = shift; 37 my %p = @_; 38 39 local $?; 40 eval { 41 my $sender = Mail::Sender->new( 42 { 43 from => $self->{from} || 'LogDispatch@foo.bar', 44 replyto => $self->{from} || 'LogDispatch@foo.bar', 45 to => ( join ',', @{ $self->{to} } ), 46 subject => $self->{subject}, 47 smtp => $self->{smtp}, 48 } 49 ); 50 51 die "Error sending mail ($sender): $Mail::Sender::Error" 52 unless ref $sender; 53 54 ref $sender->MailMsg( { msg => $p{message} } ) 55 or die "Error sending mail: $Mail::Sender::Error"; 56 }; 57 58 warn $@ if $@; 59} 60 611; 62 63# ABSTRACT: Subclass of Log::Dispatch::Email that uses the Mail::Sender module 64 65__END__ 66 67=pod 68 69=head1 NAME 70 71Log::Dispatch::Email::MailSender - Subclass of Log::Dispatch::Email that uses the Mail::Sender module 72 73=head1 VERSION 74 75version 2.34 76 77=head1 SYNOPSIS 78 79 use Log::Dispatch; 80 81 my $log = Log::Dispatch->new( 82 outputs => [ 83 [ 84 'Email::MailSender', 85 min_level => 'emerg', 86 to => [qw( foo@example.com bar@example.org )], 87 subject => 'Big error!' 88 ] 89 ], 90 ); 91 92 $log->emerg("Something bad is happening"); 93 94=head1 DESCRIPTION 95 96This is a subclass of L<Log::Dispatch::Email> that implements the send_email 97method using the L<Mail::Sender> module. 98 99=head1 AUTHOR 100 101Dave Rolsky <autarch@urth.org> 102 103=head1 COPYRIGHT AND LICENSE 104 105This software is Copyright (c) 2011 by Dave Rolsky. 106 107This is free software, licensed under: 108 109 The Artistic License 2.0 (GPL Compatible) 110 111=cut 112