line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::OpenMbox::Client; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
67272
|
use 5.006; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
6
|
1
|
|
|
1
|
|
840
|
use MIME::Lite; |
|
1
|
|
|
|
|
34174
|
|
|
1
|
|
|
|
|
49
|
|
7
|
1
|
|
|
1
|
|
468
|
use MIME::Words qw(encode_mimewords); |
|
1
|
|
|
|
|
1309
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
7
|
use MIME::Base64; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
9
|
1
|
|
|
1
|
|
427
|
use Authen::SASL; |
|
1
|
|
|
|
|
1089
|
|
|
1
|
|
|
|
|
8
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
App::OpenMbox::Client - A perl client to send simple email via OpenMbox's smtp server |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Version 0.13 |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=cut |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 SYNOPSIS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
This module can send simple email via smtp server provided by OpenMbox or any others. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Before installation you should have Net::SSLeay pre-installed, which can be fetched by this way on Ubuntu. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sudo apt install libnet-ssleay-perl |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
You can send email with OpenMbox's smtp server, which accepts smtp connection on port 587. Also you can use other provider's smtp servers, for example, gmail, pobox etc. They generally require connection to port 465 with SSL enabled. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
use App::OpenMbox::Client; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $client = App::OpenMbox::Client->new('user@openmbox.net','some.pass'); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# sending a plain text |
39
|
|
|
|
|
|
|
$client->sendmail(recepients => 'xx@a.com,xx@b.com', |
40
|
|
|
|
|
|
|
type => 'text/plain', |
41
|
|
|
|
|
|
|
subject => 'greetings', |
42
|
|
|
|
|
|
|
body => 'how are you doing today?', |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# sending a jpeg image |
46
|
|
|
|
|
|
|
$client->sendmail(recepients => 'xx@a.com,xx@b.com', |
47
|
|
|
|
|
|
|
type => 'image/jpeg', |
48
|
|
|
|
|
|
|
subject => 'a picture', |
49
|
|
|
|
|
|
|
path => '/tmp/aaa.jpeg', |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# sending with pobox's smtp server |
53
|
|
|
|
|
|
|
my $client = App::OpenMbox::Client->new('user@pobox.com','some.pass'); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$client->sendmail(recepients => 'xx@a.com,xx@b.com', |
56
|
|
|
|
|
|
|
host => 'smtp.pobox.com', |
57
|
|
|
|
|
|
|
port => 465, |
58
|
|
|
|
|
|
|
ssl => 1, |
59
|
|
|
|
|
|
|
debug => 1, |
60
|
|
|
|
|
|
|
type => 'text/plain', |
61
|
|
|
|
|
|
|
subject => 'hello', |
62
|
|
|
|
|
|
|
body => 'how are you!', |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 EXPORT |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 new |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
New the instance by providing email account and password. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=cut |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
77
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
78
|
0
|
|
|
|
|
|
my $user = shift; |
79
|
0
|
|
|
|
|
|
my $pass = shift; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
bless {user=>$user,pass=>$pass}, $class; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 sendmail |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Send email with specified arguments. The argument names can be, |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
recepients - the recepient addresses, multi-ones splitted by "," |
89
|
|
|
|
|
|
|
host - smtp host, optional, default to 'mail.openmbox.net' |
90
|
|
|
|
|
|
|
port - smtp port, optional, default to 587 |
91
|
|
|
|
|
|
|
ssl - optional, default 0 for non-SSL connection |
92
|
|
|
|
|
|
|
debug - optional, default 0 for no debug mode |
93
|
|
|
|
|
|
|
type - mime type such as text/plain, text/html etc, see MIME::Lite |
94
|
|
|
|
|
|
|
subject - message subject |
95
|
|
|
|
|
|
|
body - message body |
96
|
|
|
|
|
|
|
path - path to get the attachment such as 'image/jpeg' |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=cut |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub sendmail { |
102
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
103
|
0
|
|
|
|
|
|
my %args = @_; |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $user = $self->{'user'}; |
106
|
0
|
|
|
|
|
|
my $pass = $self->{'pass'}; |
107
|
0
|
|
0
|
|
|
|
my $recepients = $args{'recepients'} || die "no recepients provided"; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
my $host = $args{'host'} ? $args{'host'} : 'mail.openmbox.net'; |
110
|
0
|
0
|
|
|
|
|
my $port = $args{'port'} ? $args{'port'} : 587; |
111
|
0
|
0
|
|
|
|
|
my $ssl = $args{'ssl'} ? 1 : 0; |
112
|
0
|
0
|
|
|
|
|
my $debug = $args{'debug'} ? 1 : 0; |
113
|
0
|
0
|
|
|
|
|
my $type = $args{'type'} ? $args{'type'} : 'text/plain'; |
114
|
0
|
0
|
|
|
|
|
my $subject = exists($args{'subject'}) ? $args{'subject'} : undef; |
115
|
0
|
0
|
|
|
|
|
my $body = exists($args{'body'}) ? $args{'body'} : undef; |
116
|
0
|
0
|
|
|
|
|
my $path= exists($args{'path'}) ? $args{'path'} : undef; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
$subject = encode_mimewords($subject,'Charset','UTF-8'); |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
my $msg = MIME::Lite->new ( |
121
|
|
|
|
|
|
|
From => $user, |
122
|
|
|
|
|
|
|
To => $recepients, |
123
|
|
|
|
|
|
|
Subject => $subject, |
124
|
|
|
|
|
|
|
Type => $type, |
125
|
|
|
|
|
|
|
Data => $body, |
126
|
|
|
|
|
|
|
Path => $path, |
127
|
|
|
|
|
|
|
Encoding => 'base64', |
128
|
|
|
|
|
|
|
) or die "create container failed: $!"; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$msg->attr('content-type.charset' => 'UTF-8'); |
131
|
0
|
|
|
|
|
|
$msg->send( 'smtp', |
132
|
|
|
|
|
|
|
$host, |
133
|
|
|
|
|
|
|
Port => $port, |
134
|
|
|
|
|
|
|
AuthUser => $user, |
135
|
|
|
|
|
|
|
AuthPass => $pass, |
136
|
|
|
|
|
|
|
SSL => $ssl, |
137
|
|
|
|
|
|
|
Debug => $debug, |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 AUTHOR |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Henry R, C<< >> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 BUGS |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
149
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
150
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head1 SUPPORT |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
perldoc App::OpenMbox::Client |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
You can also look for information at: |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=over 4 |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
L |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=item * CPAN Ratings |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
L |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item * Search CPAN |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
L |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This software is Copyright (c) 2022 by Henry R. |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
This is free software, licensed under: |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
The Artistic License 2.0 (GPL Compatible) |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
1; # End of App::OpenMbox::Client |