Email 0.05, added doc section on using with TT
[catagits/Catalyst-Plugin-Email.git] / README
CommitLineData
5a5a0df4 1NAME
2 Catalyst::Plugin::Email - Send emails with Catalyst
3
4SYNOPSIS
5 use Catalyst 'Email';
6
95b3de58 7 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
5a5a0df4 8
9 $c->email(
10 header => [
11 From => 'sri@oook.de',
12 To => 'sri@cpan.org',
13 Subject => 'Hello!'
14 ],
15 body => 'Hello sri'
16 );
17
18DESCRIPTION
19 Send emails with Catalyst and Email::Send and Email::MIME::Creator.
20
95b3de58 21USING WITH A VIEW
22 A common practice is to handle emails using the same template language
23 used for HTML pages. This can be accomplished by pairing this plugin
24 with Catalyst::Plugin::SubRequest.
25
26 Here is a short example of rendering an email from a Template Toolkit
27 source file. The call to $c->subreq makes an internal call to the
28 render_email method just like an external call from a browser. The
29 request will pass through the end method to be processed by your View
30 class.
31
32 sub send_email : Local {
33 my ( $self, $c ) = @_;
34
35 $c->email(
36 header => [
37 To => 'me@localhost',
38 Subject => 'A TT Email',
39 ],
40 body => $c->subreq( '/render_email' ),
41 );
42 # redirect or display a message
43 }
44
45 sub render_email : Local {
46 my ( $self, $c ) = @_;
47
48 $c->stash(
49 names => [ qw/andyg sri mst/ ],
50 template => 'email.tt',
51 );
52 }
53
54 And the template:
55
56 [%- FOREACH name IN names -%]
57 Hi, [% name %]!
58 [%- END -%]
59
60 --
61 Regards,
62 Us
63
64 Output:
65
66 Hi, andyg!
67 Hi, sri!
68 Hi, mst!
69
70 --
71 Regards,
72 Us
73
74METHODS
75 email
5a5a0df4 76SEE ALSO
95b3de58 77 Catalyst, Catalyst::Plugin::SubRequest, Email::Send,
78 Email::MIME::Creator
5a5a0df4 79
80AUTHOR
81 Sebastian Riedel, "sri@cpan.org"
82
83COPYRIGHT
84 This program is free software, you can redistribute it and/or modify it
85 under the same terms as Perl itself.
86