Email: Applied Carl Franks' doc patch
Andy Grundman [Wed, 21 Dec 2005 21:23:19 +0000 (21:23 +0000)]
Changes
Email.pm

diff --git a/Changes b/Changes
index 03964e5..87ccd00 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Catalyst::Plugin::Email.
 
+0.06
+        - Added more extensive docs on config and usage.
+          (Carl Franks)
+
 0.05  Thu Nov 17 22:00:00 2005
         - Added docs on sending email using a TT template.
           (Andy Grundman)
index 54f2c50..15c0e45 100644 (file)
--- a/Email.pm
+++ b/Email.pm
@@ -5,7 +5,7 @@ use Email::Send;
 use Email::MIME;
 use Email::MIME::Creator;
 
-our $VERSION = '0.05';
+our $VERSION = '0.06';
 
 =head1 NAME
 
@@ -30,6 +30,88 @@ Catalyst::Plugin::Email - Send emails with Catalyst
 
 Send emails with Catalyst and L<Email::Send> and L<Email::MIME::Creator>.
 
+=head1 CONFIGURATION
+
+C<config> accepts the same options as L<Email::Send>.
+
+To send using the system's C<sendmail> program, set C<config> like so:
+
+    __PACKAGE__->config->{email} = ['Sendmail'];
+
+To send using authenticated SMTP:
+
+    __PACKAGE__->config->{email} = [
+        'SMTP', 
+        'smtp.myhost.com', 
+        username => $USERNAME, 
+        password => $PASSWORD, 
+    ];
+
+For different methods of sending emails, and appropriate C<config> options, 
+see L<Email::Send::NNTP>, L<Email::Send::Qmail>, L<Email::Send::SMTP> and 
+L<Email::Send::Sendmail>.
+
+=head1 METHODS
+
+=head2 email
+
+C<email()> accepts the same arguments as L<Email::MIME::Creator>'s 
+C<create()>.
+
+    $c->email(
+        header => [
+            To      => 'me@localhost',
+            Subject => 'A TT Email',
+        ],
+        body => $c->subreq( '/render_email' ),
+    );
+
+To send a multipart message, include a C<parts> argument containing an 
+arrayref of Email::MIME objects.
+
+    my @parts = (
+        Email::MIME->create(
+            attributes => {
+                content_type => 'application/pdf',
+                encoding     => 'quoted-printable',
+                name         => 'report.pdf',
+            },
+            body => $FILE_DATA,
+        ),
+        Email::MIME->create(
+            attributes => {
+                content_type => 'text/plain',
+                disposition  => 'attachment',
+                charset      => 'US-ASCII',
+            },
+            body => $c->subreq( '/render_email' ),
+        ),
+    );
+    
+    $c->email(
+        header => [
+            To      => 'me@localhost',
+            Subject => 'A TT Email',
+        ],
+        parts => \@parts,
+    );
+
+=cut
+
+sub email {
+    my $c = shift;
+    my $email = $_[1] ? {@_} : $_[0];
+    $email = Email::MIME->create(%$email);
+    my $args = $c->config->{email} || [];
+    my @args = @{$args};
+    my $class;
+    unless ( $class = shift @args ) {
+        $class = 'SMTP';
+        unshift @args, 'localhost';
+    }
+    send $class => $email, @args;
+}
+
 =head1 USING WITH A VIEW
 
 A common practice is to handle emails using the same template language used
@@ -83,26 +165,6 @@ Output:
     Regards,
     Us
 
-=head1 METHODS
-
-=head2 email
-
-=cut
-
-sub email {
-    my $c = shift;
-    my $email = $_[1] ? {@_} : $_[0];
-    $email = Email::MIME->create(%$email);
-    my $args = $c->config->{email} || [];
-    my @args = @{$args};
-    my $class;
-    unless ( $class = shift @args ) {
-        $class = 'SMTP';
-        unshift @args, 'localhost';
-    }
-    send $class => $email, @args;
-}
-
 =head1 SEE ALSO
 
 L<Catalyst>, L<Catalyst::Plugin::SubRequest>, L<Email::Send>,
@@ -112,6 +174,12 @@ L<Email::MIME::Creator>
 
 Sebastian Riedel, C<sri@cpan.org>
 
+=head1 THANKS
+
+Andy Grundman - Additional documentation
+
+Carl Franks - Additional documentation
+
 =head1 COPYRIGHT
 
 This program is free software, you can redistribute it and/or modify it