File Coverage

blib/lib/Email/Send/YYClouds.pm
Criterion Covered Total %
statement 12 14 85.7
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 17 19 89.4


line stmt bran cond sub pod time code
1             package Email::Send::YYClouds;
2              
3 1     1   13109 use 5.006;
  1         2  
4 1     1   3 use strict;
  1         0  
  1         17  
5 1     1   2 use warnings;
  1         4  
  1         25  
6 1     1   474 use utf8;
  1         9  
  1         3  
7 1     1   248 use MIME::Lite;
  0            
  0            
8             use MIME::Words qw(encode_mimewords);
9              
10             =encoding utf8
11              
12             =head1 NAME
13              
14             Email::Send::YYClouds - Send email using YYClouds' smtp server
15              
16             =head1 VERSION
17              
18             Version 0.02
19              
20             =cut
21              
22             our $VERSION = '0.02';
23              
24              
25             =head1 SYNOPSIS
26              
27             use Email::Send::YYClouds;
28              
29             my $msg = Email::Send::YYClouds->new();
30             $msg->send(recepient => ['user@yy.com','user@163.com'],
31             subject => '测试邮件',
32             body => '

这是一封测试邮件

Just a test message for you

',
33             is_html => 1,
34             );
35              
36              
37             =head1 SUBROUTINES/METHODS
38              
39             =head2 new
40            
41             $msg = Email::Send::YYClouds->new();
42             $msg = Email::Send::YYClouds->new(debug=>1); # with debug open
43              
44             =cut
45              
46             sub new {
47              
48             my $class = shift;
49             my %args = @_;
50             my $debug = $args{'debug'};
51              
52             $debug = 0 unless defined $debug;
53             bless { debug=>$debug },$class;
54             }
55              
56             =head2 send
57              
58             $msg->send(recepient => [a list of recepients],
59             subject => $subject,
60             body => $body,
61             is_html => $boolean,
62             );
63              
64             Default sender should always be noreply@yyclouds.com, you can't change it.
65              
66             recepient - a list of email addresses for receiving message.
67              
68             subject - email subject, which can be either Chinese or non-Chinese.
69              
70             body - message body, which can be either Chinese or non-Chinese.
71              
72             is_html - default 0, it must be set to 1 if this is a html message.
73              
74             Please notice: Only when MTA relay has authorized the sender host from where you can send messages.
75              
76             Otherwise you will get error:
77              
78             SMTP recipient() command failed:
79             5.7.1 : Relay access denied
80              
81             Contact the sysops to authorize it.
82              
83             =cut
84              
85             sub send {
86              
87             my $self = shift;
88             my %args = @_;
89              
90             my $recepient = $args{'recepient'};
91             my $subject = $args{'subject'};
92             my $body = $args{'body'};
93             my $is_html = $args{'is_html'};
94             $is_html = 0 unless defined $is_html;
95              
96             my $type = $is_html ? "text/html" : "text/plain";
97             my $to_address = join ',',@$recepient;
98             my $encoded_subject = encode_mimewords($subject,'Charset','UTF-8');
99              
100             my $msg = MIME::Lite->new (
101             From => 'noreply@yyclouds.com',
102             To => $to_address,
103             Subject => $encoded_subject,
104             Type => $type,
105             Data => $body,
106             Encoding => 'base64',
107             ) or die "create container failed: $!";
108              
109             $msg->attr('content-type.charset' => 'UTF-8');
110             $msg->send( 'smtp',
111             'smtp.game.yy.com',
112             Debug => $self->{debug}
113             );
114             }
115              
116              
117             =head1 AUTHOR
118              
119             Ken Peng, C<< >>
120              
121             =head1 BUGS
122              
123             Please report any bugs or feature requests to C, or through
124             the web interface at L. I will be notified, and then you'll
125             automatically be notified of progress on your bug as I make changes.
126              
127              
128              
129              
130             =head1 SUPPORT
131              
132             You can find documentation for this module with the perldoc command.
133              
134             perldoc Email::Send::YYClouds
135              
136              
137             You can also look for information at:
138              
139             =over 4
140              
141             =item * RT: CPAN's request tracker (report bugs here)
142              
143             L
144              
145             =item * AnnoCPAN: Annotated CPAN documentation
146              
147             L
148              
149             =item * CPAN Ratings
150              
151             L
152              
153             =item * Search CPAN
154              
155             L
156              
157             =back
158              
159              
160             =head1 ACKNOWLEDGEMENTS
161              
162              
163             =head1 LICENSE AND COPYRIGHT
164              
165             Copyright 2016 Ken Peng.
166              
167             This program is free software; you can redistribute it and/or modify it
168             under the terms of either: the GNU General Public License as published
169             by the Free Software Foundation; or the Artistic License.
170              
171             See http://dev.perl.org/licenses/ for more information.
172              
173              
174             =cut
175              
176             1; # End of Email::Send::YYClouds