use base qw/ Catalyst::View /;
-our $VERSION = '0.10';
+our $VERSION = '0.11';
__PACKAGE__->mk_accessors(qw/ mailer /);
croak "Can't send email without a valid email structure"
unless $email;
- if ( exists $self->{content_type} ) {
- $email->{content_type} ||= $self->{content_type};
+ # Default content type
+ if ( exists $self->{content_type} and not $email->{content_type} ) {
+ $email->{content_type} = $self->{content_type};
}
my $header = $email->{header} || [];
if $email->{from};
push @$header, ('Subject' => delete $email->{subject})
if $email->{subject};
- push @$header, ('Content-type' => delete $email->{content_type})
+ push @$header, ('Content-type' => $email->{content_type})
if $email->{content_type};
my $parts = $email->{parts};
croak "Can't send email without parts or body, check stash";
}
- my %mime = ( header => $header );
+ my %mime = ( header => $header, attributes => {} );
if ( $parts and ref $parts eq 'ARRAY' ) {
$mime{parts} = $parts;
} else {
$mime{body} = $body;
}
-
+
+ $mime{attributes}->{content_type} = $email->{content_type}
+ if $email->{content_type};
if ( $mime{attributes} and not $mime{attributes}->{charset} and
$self->{default}->{charset} )
{
use base qw/ Catalyst::View::Email /;
-our $VERSION = '0.10';
+our $VERSION = '0.11';
=head1 NAME
from => 'no-reply@foobar.com',
subject => 'I am a Catalyst generated email',
template => 'test.tt',
+ content_type => 'multipart/alternative'
};
$c->forward( $c->view('Email::Template') );
plan skip_all => 'Catalyst::View::TT required for Template tests';
exit;
}
-plan tests => 10;
+plan tests => 11;
use_ok('Catalyst::Test', 'TestApp');
cmp_ok(@emails, '==', 1, 'got emails');
isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+
+like($emails[0]->content_type, qr#^multipart/alternative#, 'Multipart email');
+
my @parts = $emails[0]->parts;
cmp_ok(@parts, '==', 2, 'got parts');
-is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain ok');
+is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain part ok');
like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
is($parts[1]->content_type, 'text/html; charset="us-ascii"', 'text/html ok');
$c->stash->{time} = $c->req->params->{time} || time;
$c->stash->{email} = {
- to => 'test-email@example.com',
- from => 'no-reply@example.com',
- subject => 'Just a test',
+ to => 'test-email@example.com',
+ from => 'no-reply@example.com',
+ subject => 'Just a test',
+ content_type => 'multipart/alternative',
templates => [
{
template => 'text_plain/test.tt',