| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Luka::Mailer; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Mailer.pm,v 1.3 2006/02/27 21:43:59 toni Exp $ |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
11
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
66
|
|
|
6
|
2
|
|
|
2
|
|
1974
|
use Mail::SendEasy; |
|
|
2
|
|
|
|
|
133610
|
|
|
|
2
|
|
|
|
|
85
|
|
|
7
|
2
|
|
|
2
|
|
2527
|
use Data::Dumper; |
|
|
2
|
|
|
|
|
21829
|
|
|
|
2
|
|
|
|
|
6733
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Luka::Mailer - wrapper around Mail::SendEasy |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $mess = Luka::Mailer->new |
|
16
|
|
|
|
|
|
|
( to => "some@some.org", |
|
17
|
|
|
|
|
|
|
cc => "bla@bla.org", |
|
18
|
|
|
|
|
|
|
subject => "some message", |
|
19
|
|
|
|
|
|
|
from => "me@bla.org", |
|
20
|
|
|
|
|
|
|
body => "lots of text. ta.\n" |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ($mess->send("Email sent")) { |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
do_something(); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
} else { |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
warn "Couldn't sent email"; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
|
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
37
|
0
|
|
0
|
|
|
|
my $class = ref($self) || $self; |
|
38
|
0
|
|
|
|
|
|
my %args = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $obj = { }; |
|
41
|
0
|
|
|
|
|
|
bless $obj, $class; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $mail = Mail::SendEasy->new( |
|
44
|
|
|
|
|
|
|
smtp => 'localhost' , |
|
45
|
|
|
|
|
|
|
); |
|
46
|
0
|
|
|
|
|
|
my $f; |
|
47
|
0
|
|
|
|
|
|
foreach my $field (keys %args) { |
|
48
|
0
|
0
|
|
|
|
|
$f = $field eq "body" ? "message" : $field; |
|
49
|
0
|
|
|
|
|
|
push @{$obj->{opts}}, $f, $args{$field}; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
}; |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$obj->{mail} = $mail; |
|
53
|
0
|
|
|
|
|
|
return $obj; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub error { |
|
57
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
|
58
|
0
|
|
|
|
|
|
return $self->{mail}->error; |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub send { |
|
62
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my @opts = $self->{opts}; |
|
65
|
0
|
|
|
|
|
|
my $status = $self->{mail}->send(@{$self->{opts}}); |
|
|
0
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
if (!$status) { print $self->error . "\n" ; return } |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
else { return 1 } |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
L, L |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 AUTHOR |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Toni Prug |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Copyright (c) 2006. Toni Prug. All rights reserved. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
86
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
|
87
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at |
|
88
|
|
|
|
|
|
|
your option) any later version. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but |
|
91
|
|
|
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
92
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
93
|
|
|
|
|
|
|
General Public License for more details. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
|
96
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
|
97
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
|
98
|
|
|
|
|
|
|
USA |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
See L |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |