1package Log::Dispatch::Email::MailSendmail; 2 3use strict; 4use warnings; 5 6use Log::Dispatch::Email; 7 8use base qw( Log::Dispatch::Email ); 9 10use Mail::Sendmail (); 11 12our $VERSION = '1.20'; 13 14 15sub send_email 16{ 17 my $self = shift; 18 my %p = @_; 19 20 my %mail = ( To => (join ',', @{ $self->{to} }), 21 Subject => $self->{subject}, 22 Message => $p{message}, 23 # Mail::Sendmail insists on having this parameter. 24 From => $self->{from} || 'LogDispatch@foo.bar', 25 ); 26 27 local $?; 28 unless ( Mail::Sendmail::sendmail(%mail) ) 29 { 30 warn "Error sending mail: $Mail::Sendmail::error" if warnings::enabled(); 31 } 32} 33 34 351; 36 37__END__ 38 39=head1 NAME 40 41Log::Dispatch::Email::MailSendmail - Subclass of Log::Dispatch::Email that uses the Mail::Sendmail module 42 43=head1 SYNOPSIS 44 45 use Log::Dispatch::Email::MailSendmail; 46 47 my $email = 48 Log::Dispatch::Email::MailSendmail->new 49 ( name => 'email', 50 min_level => 'emerg', 51 to => [ qw( foo@bar.com bar@baz.org ) ], 52 subject => 'Oh no!!!!!!!!!!!', ); 53 54 $email->log( message => 'Something bad is happening', level => 'emerg' ); 55 56=head1 DESCRIPTION 57 58This is a subclass of Log::Dispatch::Email that implements the 59send_email method using the Mail::Sendmail module. 60 61=head1 METHODS 62 63=over 4 64 65=item * new 66 67This method takes a hash of parameters. The following options are 68valid: 69 70=over 8 71 72=item * name ($) 73 74The name of the object (not the filename!). Required. 75 76=item * min_level ($) 77 78The minimum logging level this object will accept. See the 79Log::Dispatch documentation on L<Log Levels|Log::Dispatch/"Log Levels"> for more information. Required. 80 81=item * max_level ($) 82 83The maximum logging level this obejct will accept. See the 84Log::Dispatch documentation on L<Log Levels|Log::Dispatch/"Log Levels"> for more information. This is not 85required. By default the maximum is the highest possible level (which 86means functionally that the object has no maximum). 87 88=item * subject ($) 89 90The subject of the email messages which are sent. Defaults to "$0: 91log email" 92 93=item * to ($ or \@) 94 95Either a string or a list reference of strings containing email 96addresses. Required. 97 98=item * from ($) 99 100A string containing an email address. This is optional and may not 101work with all mail sending methods. 102 103NOTE: The Mail::Sendmail module requires an address be passed to it to 104set this in the mail it sends. We pass in 'LogDispatch@foo.bar' as 105the default. 106 107=item * buffered (0 or 1) 108 109This determines whether the object sends one email per message it is 110given or whether it stores them up and sends them all at once. The 111default is to buffer messages. 112 113=item * callbacks( \& or [ \&, \&, ... ] ) 114 115This parameter may be a single subroutine reference or an array 116reference of subroutine references. These callbacks will be called in 117the order they are given and passed a hash containing the following keys: 118 119 ( message => $log_message, level => $log_level ) 120 121The callbacks are expected to modify the message and then return a 122single scalar containing that modified message. These callbacks will 123be called when either the C<log> or C<log_to> methods are called and 124will only be applied to a given message once. 125 126=back 127 128=item * log_message( level => $, message => $ ) 129 130Sends a message if the level is greater than or equal to the object's 131minimum level. 132 133=back 134 135=head1 AUTHOR 136 137Dave Rolsky, <autarch@urth.org> 138 139=cut 140