X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=Email.pm;h=d909b53f31fcd30377adad336f848174dbf7cb82;hb=b6568b039ee2c8e80350ccfadaad1c561733a2fc;hp=54f2c50b2102348386309515ad71e43599c8094c;hpb=95b3de58e21a7d978bc17b66632f873636978cb3;p=catagits%2FCatalyst-Plugin-Email.git diff --git a/Email.pm b/Email.pm index 54f2c50..d909b53 100644 --- a/Email.pm +++ b/Email.pm @@ -4,8 +4,9 @@ use strict; use Email::Send; use Email::MIME; use Email::MIME::Creator; +use Carp qw/croak/; -our $VERSION = '0.05'; +our $VERSION = '0.07'; =head1 NAME @@ -30,6 +31,88 @@ Catalyst::Plugin::Email - Send emails with Catalyst Send emails with Catalyst and L and L. +=head1 CONFIGURATION + +C accepts the same options as L. + +To send using the system's C program, set C 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 options, +see L, L, L and +L. + +=head1 METHODS + +=head2 email + +C accepts the same arguments as L's +C. + + $c->email( + header => [ + To => 'me@localhost', + Subject => 'A TT Email', + ], + body => $c->subreq( '/render_email' ), + ); + +To send a multipart message, include a C 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 +166,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, L, L, @@ -112,6 +175,12 @@ L Sebastian Riedel, C +=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