1 package Catalyst::Plugin::Email;
6 use Email::MIME::Creator;
12 Catalyst::Plugin::Email - Send emails with Catalyst
18 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
22 From => 'sri@oook.de',
31 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
33 =head1 USING WITH A VIEW
35 A common practice is to handle emails using the same template language used
36 for HTML pages. This can be accomplished by pairing this plugin with
37 L<Catalyst::Plugin::SubRequest>.
39 Here is a short example of rendering an email from a Template Toolkit source
40 file. The call to $c->subreq makes an internal call to the render_email
41 method just like an external call from a browser. The request will pass
42 through the end method to be processed by your View class.
44 sub send_email : Local {
45 my ( $self, $c ) = @_;
50 Subject => 'A TT Email',
52 body => $c->subreq( '/render_email' ),
54 # redirect or display a message
57 sub render_email : Local {
58 my ( $self, $c ) = @_;
61 names => [ qw/andyg sri mst/ ],
62 template => 'email.tt',
68 [%- FOREACH name IN names -%]
94 my $email = $_[1] ? {@_} : $_[0];
95 $email = Email::MIME->create(%$email);
96 my $args = $c->config->{email} || [];
99 unless ( $class = shift @args ) {
101 unshift @args, 'localhost';
103 send $class => $email, @args;
108 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
109 L<Email::MIME::Creator>
113 Sebastian Riedel, C<sri@cpan.org>
117 This program is free software, you can redistribute it and/or modify it
118 under the same terms as Perl itself.