use warnings;
use strict;
+use Class::C3;
use Carp;
use Email::Send;
use base qw|Catalyst::View|;
-our $VERSION = '0.01';
+our $VERSION = '0.07';
-__PACKAGE__->mk_accessors('mailer');
+__PACKAGE__->mk_accessors(qw(sender stash_key content_type mailer));
=head1 NAME
=head1 CONFIGURATION
In your app configuration (example in L<YAML>):
+
View::Email:
stash_key: email
content_type: text/plain
sender:
method: SMTP
- host: smtp.myhost.com
- username: username
- password: password
+ # mailer_args is passed directly into Email::Send
+ mailer_args:
+ Host: smtp.example.com # defaults to localhost
+ username: username
+ password: password
+
+=head2 NOTE ON SMTP
+
+If you use SMTP and don't specify Host, it will default to localhost and
+attempt delivery. This often times means an email will sit in a queue
+somewhere and not be delivered.
=cut
sub controller : Private {
my ( $self, $c ) = @_;
$c->stash->{email} = {
- to => qq{catalyst@rocksyoursocks.com},
- from => qq{no-reply@socksthatarerocked.com},
+ to => q{catalyst@rocksyoursocks.com},
+ from => q{no-reply@socksthatarerocked.com},
subject => qq{Your Subject Here},
body => qq{Body Body Body}
};
=head1 OTHER MAILERS
-Now, it's no fun to just send out email using plain strings. We also have
-L<Catalyst::View::Email::TT> for use. You can also toggle this as being used
-by setting up your configuration to look like this:
+Now, it's no fun to just send out email using plain strings. We also
+have L<Catalyst::View::Email::Template> for use. You can also toggle
+this as being used by setting up your configuration to look like this:
View::Email:
- default: TT
+ default_view: TT
-Then, Catalyst::View::Email will forward to View::Email::TT by default.
+Then, Catalyst::View::Email will forward to your View::TT by default.
=cut
sub new {
- my ( $class ) = shift;
- my $self = $class->next::method(@_);
+ my $self = shift->next::method(@_);
+
+ my ( $c, $arguments ) = @_;
my $mailer = Email::Send->new;
- if ( my $method = $self->config->{sender}->{method} ) {
+ if ( my $method = $self->sender->{method} ) {
croak "$method is not supported, see Email::Send"
unless $mailer->mailer_available($method);
$mailer->mailer($method);
}
}
- if ( $mailer->mailer eq 'SMTP' ) {
- my $host = $self->config->{sender}->{host} || 'localhost';
- $mailer->mailer_args([ Host => $host ]);
+ if ( my $args = $self->sender->{mailer_args} ) {
+ if ( ref $args eq 'HASH' ) {
+ $mailer->mailer_args([ %$args ]);
+ }
+ elsif ( ref $args eq 'ARRAY' ) {
+ $mailer->mailer_args($args);
+ } else {
+ croak "Invalid mailer_args specified, check pod for Email::Send!";
+ }
}
$self->mailer($mailer);
croak "Unable to send mail, bad mail configuration"
unless $self->mailer;
- my $email = $c->stash->{$self->config->{stash_key}};
+ my $email = $c->stash->{$self->stash_key};
croak "Can't send email without a valid email structure"
unless $email;
- if ( $self->config->{content_type} ) {
- $email->{content_type} ||= $self->config->{content_type};
+ if ( $self->content_type ) {
+ $email->{content_type} ||= $self->content_type;
}
my $header = $email->{header} || [];
my $message = Email::MIME->create(%mime);
if ( $message ) {
- $self->mailer->send($message);
+ my $return = $self->mailer->send($message);
+ croak "$return" if !$return;
} else {
croak "Unable to create message";
}
J. Shirley <jshirley@gmail.com>
+=head1 CONTRIBUTORS
+
+(Thanks!)
+
+Matt S Trout
+
+Daniel Westermann-Clark
+
+Simon Elliott <cpan@browsing.co.uk> - ::Template
+
+Roman Filippov
+
=head1 LICENSE
This library is free software, you can redistribute it and/or modify it under