changed docs to say DEPRECATED in favour of Email::MIME::Kit or Catalyst::View::Email...
[catagits/Catalyst-Plugin-Email.git] / Email.pm
index 7945e66..87b6ca0 100644 (file)
--- a/Email.pm
+++ b/Email.pm
@@ -6,14 +6,16 @@ use Email::MIME;
 use Email::MIME::Creator;
 use Carp qw/croak/;
 
-our $VERSION = '0.06';
+our $VERSION = '0.08';
 
 =head1 NAME
 
-Catalyst::Plugin::Email - Send emails with Catalyst
+Catalyst::Plugin::Email - (DEPRECATED) Send emails with Catalyst
 
 =head1 SYNOPSIS
 
+    # please use Email::MIME::Kit or Catalyst::View::Email::Template instead
+
     use Catalyst 'Email';
 
     __PACKAGE__->config->{email} = [qw/SMTP smtp.oook.de/];
@@ -102,8 +104,6 @@ arrayref of Email::MIME objects.
 sub email {
     my $c = shift;
     my $email = $_[1] ? {@_} : $_[0];
-    croak "Can't send mail without recipient"
-       unless length($email->{To});
     $email = Email::MIME->create(%$email);
     my $args = $c->config->{email} || [];
     my @args = @{$args};
@@ -118,34 +118,34 @@ sub email {
 =head1 USING WITH A VIEW
 
 A common practice is to handle emails using the same template language used
-for HTML pages.  This can be accomplished by pairing this plugin with
-L<Catalyst::Plugin::SubRequest>.
-
-Here is a short example of rendering an email from a Template Toolkit source
-file.  The call to $c->subreq makes an internal call to the render_email
-method just like an external call from a browser.  The request will pass
-through the end method to be processed by your View class.
+for HTML pages.  If your view supports the 'render' method (Like the TT view 
+does), you just set the body like this:
+  $c->email(
+     header => [
+        To      => 'me@localhost',
+        Subject => 'A TT Email',
+     ],
+     body => $c->view('TT')->render($c,'mytemplate.tt'),
+  }
+
+If your view doesn't support render, you can just forward to it, then reset 
+the body like this:
 
     sub send_email : Local {
         my ( $self, $c ) = @_;  
-
+        {
+        local $c->stash->{names}   = [ qw/andyg sri mst/ ],
+        local $c->stash->{template}= 'mytemplate.tt';   
+        $c->forward($c->view('MyView'));
         $c->email(
             header => [
                 To      => 'me@localhost',
                 Subject => 'A TT Email',
             ],
-            body => $c->subreq( '/render_email' ),
-        );
-        # redirect or display a message
-    }
-    
-    sub render_email : Local {
-        my ( $self, $c ) = @_;
-        
-        $c->stash(
-            names    => [ qw/andyg sri mst/ ],
-            template => 'email.tt',
+            body => $c->res->body,
         );
+        $c->res->body(undef);
+        }
     }
     
 And the template:
@@ -176,12 +176,9 @@ L<Email::MIME::Creator>
 =head1 AUTHOR
 
 Sebastian Riedel, C<sri@cpan.org>
-
-=head1 THANKS
-
-Andy Grundman - Additional documentation
-
-Carl Franks - Additional documentation
+Andy Grundman
+Carl Franks 
+Marcus Ramberg C<mramberg@cpan.org>
 
 =head1 COPYRIGHT