1 package Catalyst::Plugin::Email;
6 use Email::MIME::Creator;
12 Catalyst::Plugin::Email - (DEPRECATED) Send emails with Catalyst
16 # please use Email::MIME::Kit or Catalyst::View::Email::Template instead
20 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
24 From => 'sri@oook.de',
33 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
37 C<config> accepts the same options as L<Email::Send>.
39 To send using the system's C<sendmail> program, set C<config> like so:
41 __PACKAGE__->config->{email} = ['Sendmail'];
43 To send using authenticated SMTP:
45 __PACKAGE__->config->{email} = [
48 username => $USERNAME,
49 password => $PASSWORD,
52 For different methods of sending emails, and appropriate C<config> options,
53 see L<Email::Send::NNTP>, L<Email::Send::Qmail>, L<Email::Send::SMTP> and
54 L<Email::Send::Sendmail>.
60 C<email()> accepts the same arguments as L<Email::MIME::Creator>'s
66 Subject => 'A TT Email',
68 body => $c->subreq( '/render_email' ),
71 To send a multipart message, include a C<parts> argument containing an
72 arrayref of Email::MIME objects.
77 content_type => 'application/pdf',
78 encoding => 'quoted-printable',
85 content_type => 'text/plain',
86 disposition => 'attachment',
87 charset => 'US-ASCII',
89 body => $c->subreq( '/render_email' ),
96 Subject => 'A TT Email',
105 my $email = $_[1] ? {@_} : $_[0];
106 $email = Email::MIME->create(%$email);
107 my $args = $c->config->{email} || [];
110 unless ( $class = shift @args ) {
112 unshift @args, 'localhost';
114 send $class => $email, @args;
117 =head1 USING WITH A VIEW
119 A common practice is to handle emails using the same template language used
120 for HTML pages. If your view supports the 'render' method (Like the TT view
121 does), you just set the body like this:
124 To => 'me@localhost',
125 Subject => 'A TT Email',
127 body => $c->view('TT')->render($c,'mytemplate.tt'),
130 If your view doesn't support render, you can just forward to it, then reset
133 sub send_email : Local {
134 my ( $self, $c ) = @_;
136 local $c->stash->{names} = [ qw/andyg sri mst/ ],
137 local $c->stash->{template}= 'mytemplate.tt';
138 $c->forward($c->view('MyView'));
141 To => 'me@localhost',
142 Subject => 'A TT Email',
144 body => $c->res->body,
146 $c->res->body(undef);
152 [%- FOREACH name IN names -%]
172 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
173 L<Email::MIME::Creator>
177 Sebastian Riedel, C<sri@cpan.org>
180 Marcus Ramberg C<mramberg@cpan.org>
184 This program is free software, you can redistribute it and/or modify it
185 under the same terms as Perl itself.