1package Log::Dispatch::Email::MailSend; 2 3use strict; 4use warnings; 5 6use Log::Dispatch::Email; 7 8use base qw( Log::Dispatch::Email ); 9 10use Mail::Send; 11 12our $VERSION = '1.19'; 13 14sub send_email 15{ 16 my $self = shift; 17 my %p = @_; 18 19 my $msg = Mail::Send->new; 20 21 $msg->to( join ',', @{ $self->{to} } ); 22 $msg->subject( $self->{subject} ); 23 24 # Does this ever work for this module? 25 $msg->set('From', $self->{from}) if $self->{from}; 26 27 local $?; 28 eval 29 { 30 my $fh = $msg->open 31 or die "Cannot open handle to mail program"; 32 33 $fh->print( $p{message} ) 34 or die "Cannot print message to mail program handle"; 35 36 $fh->close 37 or die "Cannot close handle to mail program"; 38 }; 39 40 warn $@ if $@ && warnings::enabled(); 41} 42 43 441; 45 46__END__ 47 48=head1 NAME 49 50Log::Dispatch::Email::MailSend - Subclass of Log::Dispatch::Email that uses the Mail::Send module 51 52=head1 SYNOPSIS 53 54 use Log::Dispatch::Email::MailSend; 55 56 my $email = 57 Log::Dispatch::Email::MailSend->new 58 ( name => 'email', 59 min_level => 'emerg', 60 to => [ qw( foo@bar.com bar@baz.org ) ], 61 subject => 'Oh no!!!!!!!!!!!', ); 62 63 $email->log( message => 'Something bad is happening', level => 'emerg' ); 64 65=head1 DESCRIPTION 66 67This is a subclass of Log::Dispatch::Email that implements the 68send_email method using the Mail::Send module. 69 70=head1 METHODS 71 72=over 4 73 74=item * new 75 76This method takes a hash of parameters. The following options are 77valid: 78 79=over 8 80 81=item * name ($) 82 83The name of the object (not the filename!). Required. 84 85=item * min_level ($) 86 87The minimum logging level this object will accept. See the 88Log::Dispatch documentation on L<Log Levels|Log::Dispatch/"Log Levels"> for more information. Required. 89 90=item * max_level ($) 91 92The maximum logging level this obejct will accept. See the 93Log::Dispatch documentation on L<Log Levels|Log::Dispatch/"Log Levels"> for more information. This is not 94required. By default the maximum is the highest possible level (which 95means functionally that the object has no maximum). 96 97=item * subject ($) 98 99The subject of the email messages which are sent. Defaults to "$0: 100log email" 101 102=item * to ($ or \@) 103 104Either a string or a list reference of strings containing email 105addresses. Required. 106 107=item * from ($) 108 109A string containing an email address. This is optional and may not 110work with all mail sending methods. 111 112=item * buffered (0 or 1) 113 114This determines whether the object sends one email per message it is 115given or whether it stores them up and sends them all at once. The 116default is to buffer messages. 117 118=item * callbacks( \& or [ \&, \&, ... ] ) 119 120This parameter may be a single subroutine reference or an array 121reference of subroutine references. These callbacks will be called in 122the order they are given and passed a hash containing the following keys: 123 124 ( message => $log_message, level => $log_level ) 125 126The callbacks are expected to modify the message and then return a 127single scalar containing that modified message. These callbacks will 128be called when either the C<log> or C<log_to> methods are called and 129will only be applied to a given message once. 130 131=back 132 133=item * log_message( level => $, message => $ ) 134 135Sends a message if the level is greater than or equal to the object's 136minimum level. 137 138=back 139 140=head1 CHANGING HOW MAIL IS SENT 141 142Since C<Mail::Send> is a subclass of C<Mail::Mailer>, you can change 143how mail is sent from this module by simply C<use>ing C<Mail::Mailer> 144in your code before mail is sent. For example, to send mail via smtp, 145you could do: 146 147 use Mail::Mailer 'smtp', Server => 'foo.example.com'; 148 149For more details, see the C<Mail::Mailer> docs. 150 151=head1 AUTHOR 152 153Dave Rolsky, <autarch@urth.org> 154 155=head1 SEE ALSO 156 157 158Log::Dispatch, Log::Dispatch::ApacheLog, Log::Dispatch::Email, 159Log::Dispatch::Email::MailSendmail, Log::Dispatch::Email::MIMELite, 160Log::Dispatch::File, Log::Dispatch::Handle, Log::Dispatch::Output, 161Log::Dispatch::Screen, Log::Dispatch::Syslog 162 163=cut 164