1 package Catalyst::Plugin::Email;
6 use Email::MIME::Creator;
13 Catalyst::Plugin::Email - (DEPRECATED) Send emails with Catalyst
17 # please use Email::MIME::Kit or Catalyst::View::Email::Template instead
21 __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
25 From => 'sri@oook.de',
34 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
38 C<config> accepts the same options as L<Email::Send>.
40 To send using the system's C<sendmail> program, set C<config> like so:
42 __PACKAGE__->config->{email} = ['Sendmail'];
44 To send using authenticated SMTP:
46 __PACKAGE__->config->{email} = [
49 username => $USERNAME,
50 password => $PASSWORD,
53 For different methods of sending emails, and appropriate C<config> options,
54 see L<Email::Send::NNTP>, L<Email::Send::Qmail>, L<Email::Send::SMTP> and
55 L<Email::Send::Sendmail>.
61 C<email()> accepts the same arguments as L<Email::MIME::Creator>'s
67 Subject => 'A TT Email',
69 body => $c->subreq( '/render_email' ),
72 To send a multipart message, include a C<parts> argument containing an
73 arrayref of Email::MIME objects.
78 content_type => 'application/pdf',
79 encoding => 'quoted-printable',
86 content_type => 'text/plain',
87 disposition => 'attachment',
88 charset => 'US-ASCII',
90 body => $c->subreq( '/render_email' ),
97 Subject => 'A TT Email',
106 my $email = $_[1] ? {@_} : $_[0];
107 $email = Email::MIME->create(%$email);
108 my $args = $c->config->{email} || [];
111 unless ( $class = shift @args ) {
113 unshift @args, 'localhost';
115 send $class => $email, @args;
118 =head1 USING WITH A VIEW
120 A common practice is to handle emails using the same template language used
121 for HTML pages. If your view supports the 'render' method (Like the TT view
122 does), you just set the body like this:
125 To => 'me@localhost',
126 Subject => 'A TT Email',
128 body => $c->view('TT')->render($c,'mytemplate.tt'),
131 If your view doesn't support render, you can just forward to it, then reset
134 sub send_email : Local {
135 my ( $self, $c ) = @_;
137 local $c->stash->{names} = [ qw/andyg sri mst/ ],
138 local $c->stash->{template}= 'mytemplate.tt';
139 $c->forward($c->view('MyView'));
142 To => 'me@localhost',
143 Subject => 'A TT Email',
145 body => $c->res->body,
147 $c->res->body(undef);
153 [%- FOREACH name IN names -%]
173 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
174 L<Email::MIME::Creator>
178 Sebastian Riedel, C<sri@cpan.org>
181 Marcus Ramberg C<mramberg@cpan.org>
185 This program is free software, you can redistribute it and/or modify it
186 under the same terms as Perl itself.