1 package Catalyst::Plugin::Email;
6 use Email::MIME::Creator;
13 Catalyst::Plugin::Email - Send emails with Catalyst
19 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
23 From => 'sri@oook.de',
32 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
36 C<config> accepts the same options as L<Email::Send>.
38 To send using the system's C<sendmail> program, set C<config> like so:
40 __PACKAGE__->config->{email} = ['Sendmail'];
42 To send using authenticated SMTP:
44 __PACKAGE__->config->{email} = [
47 username => $USERNAME,
48 password => $PASSWORD,
51 For different methods of sending emails, and appropriate C<config> options,
52 see L<Email::Send::NNTP>, L<Email::Send::Qmail>, L<Email::Send::SMTP> and
53 L<Email::Send::Sendmail>.
59 C<email()> accepts the same arguments as L<Email::MIME::Creator>'s
65 Subject => 'A TT Email',
67 body => $c->subreq( '/render_email' ),
70 To send a multipart message, include a C<parts> argument containing an
71 arrayref of Email::MIME objects.
76 content_type => 'application/pdf',
77 encoding => 'quoted-printable',
84 content_type => 'text/plain',
85 disposition => 'attachment',
86 charset => 'US-ASCII',
88 body => $c->subreq( '/render_email' ),
95 Subject => 'A TT Email',
104 my $email = $_[1] ? {@_} : $_[0];
105 $email = Email::MIME->create(%$email);
106 my $args = $c->config->{email} || [];
109 unless ( $class = shift @args ) {
111 unshift @args, 'localhost';
113 send $class => $email, @args;
116 =head1 USING WITH A VIEW
118 A common practice is to handle emails using the same template language used
119 for HTML pages. This can be accomplished by pairing this plugin with
120 L<Catalyst::Plugin::SubRequest>.
122 Here is a short example of rendering an email from a Template Toolkit source
123 file. The call to $c->subreq makes an internal call to the render_email
124 method just like an external call from a browser. The request will pass
125 through the end method to be processed by your View class.
127 sub send_email : Local {
128 my ( $self, $c ) = @_;
132 To => 'me@localhost',
133 Subject => 'A TT Email',
135 body => $c->subreq( '/render_email' ),
137 # redirect or display a message
140 sub render_email : Local {
141 my ( $self, $c ) = @_;
144 names => [ qw/andyg sri mst/ ],
145 template => 'email.tt',
151 [%- FOREACH name IN names -%]
171 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
172 L<Email::MIME::Creator>
176 Sebastian Riedel, C<sri@cpan.org>
180 Andy Grundman - Additional documentation
182 Carl Franks - Additional documentation
186 This program is free software, you can redistribute it and/or modify it
187 under the same terms as Perl itself.