File Coverage

blib/lib/Catalyst/Helper/Model/Email.pm
Criterion Covered Total %
statement 9 14 64.2
branch n/a
condition n/a
subroutine 3 4 75.0
pod 1 1 100.0
total 13 19 68.4


line stmt bran cond sub pod time code
1             package Catalyst::Helper::Model::Email;
2 2     2   1806 use strict;
  2         4  
  2         79  
3 2     2   11 use warnings;
  2         3  
  2         67  
4            
5 2     2   69 use 5.008_008;
  2         6  
  2         346  
6            
7             our $VERSION = '0.04';
8            
9             sub mk_compclass {
10 0     0 1   my ( $class, $helper, @mailer_args ) = @_;
11 0           my %args;
12 0           @args{qw/mailer host username password/} = @mailer_args;
13 0           $helper->render_file( 'compclass', $helper->{file}, \%args );
14 0           return;
15             }
16            
17             =head1 NAME
18            
19             Catalyst::Helper::Model::Email - Helper for Mail::Builder::Simple
20            
21             =head1 VERSION
22            
23             Version 0.03
24            
25             =head1 SYNOPSIS
26            
27             ./script/myapp_create.pl model Email1 Email SMTP smtp.host.com usr passwd
28            
29             =head1 DESCRIPTION
30            
31             Using the command line above, Catalyst::Helper::Model::Email will create C that looks like:
32            
33             package MyApp::Model::Email1;
34             use strict;
35             use warnings;
36             use base 'Catalyst::Model::Factory';
37            
38             __PACKAGE__->config(
39             class => 'Mail::Builder::Simple',
40             args => {
41             mail_client => {
42             mailer => 'SMTP',
43             mailer_args => {
44             host => 'smtp.host.com',
45             username => 'usr',
46             password => 'passwd',
47             },
48             },
49             },
50             );
51            
52             1;
53            
54             And you will be able to send email with this model, using the following code in your controllers:
55            
56             $c->model("Email1"->send(
57             from => 'me@host.com',
58             to => 'you@yourhost.com',
59             subject => 'The subject with UTF-8 chars',
60             plaintext => "Hello\n\nHow are you?\n\n",
61             );
62            
63             But you will be also able to send more complex email messages like:
64            
65             $c->model("Email1"->send(
66             from => ['me@host.com', 'My Name'],
67             to => ['you@yourhost.com', 'Your Name'],
68             subject => 'The subject with UTF-8 chars',
69             plaintext => "Hello\n\nHow are you?\n\n",
70             htmltext => "

Hello

How are you?

",
71             attachment => ['file', 'filename.pdf', 'application/pdf'],
72             image => ['logo.png', 'image_id_here'],
73             priority => 1,
74             mailer => 'My Emailer 0.01',
75             'X-Special-Header' => 'My special header',
76             );
77            
78             ...or even more complex messages, using templates.
79            
80             =head1 SUBROUTINES/METHODS
81            
82             =head2 mk_compclass
83            
84             =head1 CONFIGURATION AND ENVIRONMENT
85            
86             ./script/myapp_create.pl model Email
87            
88             You need to specify the C (the name of the model you want to create), and all other elements are optional.
89            
90             For the you should add the mailer_args parameters required by the mailer you want to use.
91            
92             If you want to use an SMTP server, you need to add just SMTP and the address of the SMTP server.
93            
94             If you want to use an SMTP server that requires authentication, you need to add SMTP, the address of the server, the username and the password, like in the exemple given above.
95            
96             The module supports the mailers supported by L. Mail::Builder::Simple uses L for sending email, so check the modules under L for finding the parameters you might need to use for each type of mailer.
97            
98             This helper can add in the model just the mailer type, the hostname, the username and the password, but you can add manually other parameters like a different port than the default, or the option for using SSL when connecting to the SMTP server.
99            
100             You can add to the generated model any other parameters you can use for sending email, for example the C field, and you won't need to specify those parameters when sending each email.
101            
102             You can also put the configuration variables in the application's main configuration file (myapp.conf), using something like:
103            
104            
105             class Mail::Builder::Simple
106            
107            
108             mailer SMTP
109            
110             host smtp.host.com
111             username myuser
112             password mypass
113            
114            
115             from me@host.com
116            
117            
118            
119             =head1 DIAGNOSTICS
120            
121             =head1 DEPENDENCIES
122            
123             L, L, L, L
124            
125             =head1 INCOMPATIBILITIES
126            
127             No known incompatibilities.
128            
129             =head1 BUGS AND LIMITATIONS
130            
131             No known bugs. If you find some, please announce.
132            
133             =head1 AUTHOR
134            
135             Octavian Rasnita C
136            
137             =head1 LICENSE AND COPYRIGHT
138            
139             This library is free software. You can redistribute it and/or modify
140             it under the same terms as perl itself.
141            
142             No copyright claim is asserted over the generated code.
143            
144             =cut
145            
146             1;
147            
148             __DATA__