1 package Catalyst::Plugin::Email;
8 use Email::MIME::Creator;
10 our $VERSION = '0.09';
14 Catalyst::Plugin::Email - (DEPRECATED) Send emails with Catalyst
18 # please use Email::MIME::Kit or Catalyst::View::Email::Template instead
22 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
26 From => 'sri@oook.de',
35 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
39 C<config> accepts the same options as L<Email::Send>.
41 To send using the system's C<sendmail> program, set C<config> like so:
43 __PACKAGE__->config->{email} = ['Sendmail'];
45 To send using authenticated SMTP:
47 __PACKAGE__->config->{email} = [
50 username => $USERNAME,
51 password => $PASSWORD,
54 For different methods of sending emails, and appropriate C<config> options,
55 see L<Email::Send::NNTP>, L<Email::Send::Qmail>, L<Email::Send::SMTP> and
56 L<Email::Send::Sendmail>.
62 C<email()> accepts the same arguments as L<Email::MIME::Creator>'s
68 Subject => 'A TT Email',
70 body => $c->subreq( '/render_email' ),
73 To send a multipart message, include a C<parts> argument containing an
74 arrayref of Email::MIME objects.
79 content_type => 'application/pdf',
80 encoding => 'quoted-printable',
87 content_type => 'text/plain',
88 disposition => 'attachment',
89 charset => 'US-ASCII',
91 body => $c->subreq( '/render_email' ),
98 Subject => 'A TT Email',
107 my $email = $_[1] ? {@_} : $_[0];
108 $email = Email::MIME->create(%$email);
109 my $args = $c->config->{email} || [];
112 unless ( $class = shift @args ) {
114 unshift @args, 'localhost';
116 send $class => $email, @args;
119 =head1 USING WITH A VIEW
121 A common practice is to handle emails using the same template language used
122 for HTML pages. If your view supports the 'render' method (Like the TT view
123 does), you just set the body like this:
126 To => 'me@localhost',
127 Subject => 'A TT Email',
129 body => $c->view('TT')->render($c,'mytemplate.tt'),
132 If your view doesn't support render, you can just forward to it, then reset
135 sub send_email : Local {
136 my ( $self, $c ) = @_;
138 local $c->stash->{names} = [ qw/andyg sri mst/ ],
139 local $c->stash->{template}= 'mytemplate.tt';
140 $c->forward($c->view('MyView'));
143 To => 'me@localhost',
144 Subject => 'A TT Email',
146 body => $c->res->body,
148 $c->res->body(undef);
154 [%- FOREACH name IN names -%]
174 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
175 L<Email::MIME::Creator>
179 Sebastian Riedel, C<sri@cpan.org>
182 Marcus Ramberg C<mramberg@cpan.org>
186 This program is free software, you can redistribute it and/or modify it
187 under the same terms as Perl itself.