line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Dispatch::Email::MailSend; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
685
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '2.71'; |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
184
|
use Mail::Send; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Try::Tiny; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use base qw( Log::Dispatch::Email ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub send_email { |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
my %p = @_; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $msg = Mail::Send->new; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$msg->to( join ',', @{ $self->{to} } ); |
20
|
|
|
|
|
|
|
$msg->subject( $self->{subject} ); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# Does this ever work for this module? |
23
|
|
|
|
|
|
|
$msg->set( 'From', $self->{from} ) if $self->{from}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
local $? = 0; |
26
|
|
|
|
|
|
|
return |
27
|
|
|
|
|
|
|
if try { |
28
|
|
|
|
|
|
|
my $fh = $msg->open |
29
|
|
|
|
|
|
|
or die 'Cannot open handle to mail program'; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$fh->print( $p{message} ) |
32
|
|
|
|
|
|
|
or die 'Cannot print message to mail program handle'; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
$fh->close |
35
|
|
|
|
|
|
|
or die 'Cannot close handle to mail program'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
warn $@ if $@; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ABSTRACT: Subclass of Log::Dispatch::Email that uses the Mail::Send module |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=encoding UTF-8 |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 NAME |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Log::Dispatch::Email::MailSend - Subclass of Log::Dispatch::Email that uses the Mail::Send module |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 VERSION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
version 2.71 |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 SYNOPSIS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use Log::Dispatch; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
my $log = Log::Dispatch->new( |
66
|
|
|
|
|
|
|
outputs => [ |
67
|
|
|
|
|
|
|
[ |
68
|
|
|
|
|
|
|
'Email::MailSend', |
69
|
|
|
|
|
|
|
min_level => 'emerg', |
70
|
|
|
|
|
|
|
to => [qw( foo@example.com bar@example.org )], |
71
|
|
|
|
|
|
|
subject => 'Big error!' |
72
|
|
|
|
|
|
|
] |
73
|
|
|
|
|
|
|
], |
74
|
|
|
|
|
|
|
); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$log->emerg('Something bad is happening'); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 DESCRIPTION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This is a subclass of L<Log::Dispatch::Email> that implements the send_email |
81
|
|
|
|
|
|
|
method using the L<Mail::Send> module. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 CHANGING HOW MAIL IS SENT |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Since L<Mail::Send> is a subclass of L<Mail::Mailer>, you can change how mail |
86
|
|
|
|
|
|
|
is sent from this module by simply C<use>ing L<Mail::Mailer> in your code |
87
|
|
|
|
|
|
|
before mail is sent. For example, to send mail via smtp, you could do: |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
use Mail::Mailer 'smtp', Server => 'foo.example.com'; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
For more details, see the L<Mail::Mailer> docs. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 SUPPORT |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Bugs may be submitted at L<https://github.com/houseabsolute/Log-Dispatch/issues>. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SOURCE |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
The source code repository for Log-Dispatch can be found at L<https://github.com/houseabsolute/Log-Dispatch>. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This software is Copyright (c) 2023 by Dave Rolsky. |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This is free software, licensed under: |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
The full text of the license can be found in the |
114
|
|
|
|
|
|
|
F<LICENSE> file included with this distribution. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |