use base qw|Catalyst::View|;
-our $VERSION = '0.02';
+our $VERSION = '0.07';
-__PACKAGE__->mk_accessors('mailer');
+__PACKAGE__->mk_accessors(qw(sender stash_key content_type mailer));
=head1 NAME
method: SMTP
# mailer_args is passed directly into Email::Send
mailer_args:
- - Host: smtp.example.com
- - username: username
- - password: password
+ 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
my $self = shift->next::method(@_);
my ( $c, $arguments ) = @_;
- $self->config($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 ( $self->config->{sender}->{mailer_args} ) {
- $mailer->mailer_args($self->config->{sender}->{mailer_args});
+ 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";
}
(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