| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package XAS::Lib::Modules::Email; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
756
|
use Try::Tiny; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
46
|
|
|
6
|
1
|
|
|
1
|
|
762
|
use MIME::Lite; |
|
|
1
|
|
|
|
|
15448
|
|
|
|
1
|
|
|
|
|
45
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Basename; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
64
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XAS::Class |
|
10
|
1
|
|
|
|
|
9
|
debug => 0, |
|
11
|
|
|
|
|
|
|
version => $VERSION, |
|
12
|
|
|
|
|
|
|
base => 'XAS::Singleton', |
|
13
|
|
|
|
|
|
|
utils => ':validation dotid compress', |
|
14
|
1
|
|
|
1
|
|
4
|
; |
|
|
1
|
|
|
|
|
1
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#use Data::Dumper; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
19
|
|
|
|
|
|
|
# Public Methods |
|
20
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub send { |
|
23
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
24
|
0
|
|
|
|
|
|
my $p = validate_params(\@_, { |
|
25
|
|
|
|
|
|
|
-to => 1, |
|
26
|
|
|
|
|
|
|
-from => 1, |
|
27
|
|
|
|
|
|
|
-subject => 1, |
|
28
|
|
|
|
|
|
|
-message => { optional => 1, default => ' '}, |
|
29
|
|
|
|
|
|
|
-attachment => { optional => 1, default => undef } |
|
30
|
|
|
|
|
|
|
}); |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $msg; |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
try { |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
0
|
|
|
if ($self->env->mxmailer eq 'smtp') { |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
MIME::Lite->send( |
|
39
|
|
|
|
|
|
|
$self->env->mxmailer, |
|
40
|
|
|
|
|
|
|
$self->env->mxserver, |
|
41
|
|
|
|
|
|
|
Timeout => $self->env->mxtimeout, |
|
42
|
|
|
|
|
|
|
Port => $self->env->mxport, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$msg = MIME::Lite->new( |
|
48
|
|
|
|
|
|
|
To => $p->{'to'}, |
|
49
|
|
|
|
|
|
|
From => $p->{'from'}, |
|
50
|
0
|
|
|
|
|
|
Subject => $p->{'subject'}, |
|
51
|
|
|
|
|
|
|
Type => 'multipart/mixed' |
|
52
|
|
|
|
|
|
|
); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$msg->attach( |
|
55
|
|
|
|
|
|
|
Type => 'TEXT', |
|
56
|
0
|
|
|
|
|
|
Data => $p->{'message'} |
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (defined($p->{'attachment'})) { |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $filename = $p->{'attachment'}; |
|
62
|
0
|
|
|
|
|
|
my ($name, $path, $suffix) = fileparse($filename, qr{\..*}); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$msg->attach( |
|
65
|
|
|
|
|
|
|
Type => 'AUTO', |
|
66
|
|
|
|
|
|
|
Path => $filename, |
|
67
|
|
|
|
|
|
|
Filename => $name . $suffix, |
|
68
|
|
|
|
|
|
|
Dispostition => 'attachment' |
|
69
|
|
|
|
|
|
|
); |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$msg->send(); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} catch { |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
|
|
my $ex = $_; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->throw_msg( |
|
80
|
|
|
|
|
|
|
dotid($self->class) . '.send.undeliverable', |
|
81
|
|
|
|
|
|
|
'enail_undeliverable', |
|
82
|
0
|
|
|
|
|
|
$p->{'to'}, |
|
83
|
|
|
|
|
|
|
compress($ex) |
|
84
|
|
|
|
|
|
|
); |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
}; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
91
|
|
|
|
|
|
|
# Private methods |
|
92
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
XAS::Lib::Modules::Email - The Email module for the XAS environment |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Your program can use this module in the following fashion: |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
package My::App; |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
use XAS::Class |
|
109
|
|
|
|
|
|
|
version => '0.01', |
|
110
|
|
|
|
|
|
|
base => 'XAS::Lib::App' |
|
111
|
|
|
|
|
|
|
; |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub main { |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
$self->email->send( |
|
116
|
|
|
|
|
|
|
-from => "me\@localhost", |
|
117
|
|
|
|
|
|
|
-to => "you\@localhost", |
|
118
|
|
|
|
|
|
|
-subject => "Testing", |
|
119
|
|
|
|
|
|
|
-message => "This is a test" |
|
120
|
|
|
|
|
|
|
); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
1; |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This is the the module for sending email within the XAS environment. It is |
|
129
|
|
|
|
|
|
|
implemented as a singleton. It can also be auto-loaded when the method 'email' |
|
130
|
|
|
|
|
|
|
is invoked. |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 METHODS |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 new |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
This method initializes the module. It uses parameters from |
|
137
|
|
|
|
|
|
|
L<XAS::Lib::Modules::Environment|XAS::Lib::Modules::Environment> to set defaults. |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 send |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This method will send an email. It takes the following parameters: |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item B<-to> |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
The SMTP address of the recipient. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item B<-from> |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
The SMTP address of the sender. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item B<-subject> |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
A subject line for the message. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item B<-message> |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
The text of the message. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item B<-attachment> |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
A file name to append to the message. |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=back |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=over 4 |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item L<XAS|XAS> |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=back |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head1 AUTHOR |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
Kevin L. Esteb, E<lt>kevin@kesteb.usE<gt> |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Copyright (C) 2014 Kevin L. Esteb |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
184
|
|
|
|
|
|
|
the terms of the Artistic License 2.0. For details, see the full text |
|
185
|
|
|
|
|
|
|
of the license at http://www.perlfoundation.org/artistic_license_2_0. |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |