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