Catalyst::Plugin::Email::Japanese - Send Japanese emails with Catalyst


Catalyst-Plugin-Email-Japanese documentation Contained in the Catalyst-Plugin-Email-Japanese distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::Email::Japanese - Send Japanese emails with Catalyst

SYNOPSIS

Top

    use Catalyst qw/Email::Japanese/;

    # config base parameters
    __PACKAGE__->config(
        email => {
            Template => 'email.tt',
            From => 'typester@cpan.org',
        }
    );

    # and later in your controller
    $c->email(
        To => 'example@example.com',
        Subject => 'Hi!',
    );

DESCRIPTION

Top

Send emails with Catalyst and MIME::Lite::TT::Japanese.

ForceUTF8 MODE

Top

If $c->config->{ForceUTF8} or $c->config->{email}->{ForceUTF8} is true value, this module use Template::Provider::Encoding and Template::Stash::ForceUTF8 for correct utf-8 handling.

Please see these module's docs for detail.

HTML MAIL SUPPORT

Top

If Template parameter is hash ref like below:

    $c->config->{email} = {
        Template => {
            html => 'html.tt',
            text => 'text.tt',
        },
    };

then this module use MIME::Lite::TT::HTML::Japanese instead of MIME::Lite::TT::Japanese.

This is useful for sending html mails.

METHODS

Top

email( %args )

Send email with MIME::Lite::TT::(HTML::)Japanese.

%args and $c->config->{emal} is MIME::Lite::TT::(HTML::)Japanese's parameters, and %args override latter.

SEE ALSO

Top

Catalyst, Catalyst::Plugin::Email, MIME::Lite::TT::Japanese, MIME::Lite::TT::HTML::Japanese.

AUTHOR

Top

Daisuke Murase <typester@cpan.org>

COPYRIGHT

Top


Catalyst-Plugin-Email-Japanese documentation Contained in the Catalyst-Plugin-Email-Japanese distribution.
package Catalyst::Plugin::Email::Japanese;
use strict;

use strict;
use Catalyst::Exception;
use UNIVERSAL::require

our $VERSION = '0.07';

sub email {
    my $c = shift;
    my $args = $_[1] ? {@_} : $_[0];

    my $template = $args->{Template} || $c->stash->{email}->{template} || $c->config->{email}->{Template};

    my $module =
        ref $template eq 'HASH'
        ? 'MIME::Lite::TT::HTML::Japanese'
        : 'MIME::Lite::TT::Japanese';
    $module->require
        or Catalyst::Exception->throw(
            message => qq/Couldn't load $module, "$!"/ );

    my $options = {
        EVAL_PERL => 0,
        %{ $c->config->{email}->{TmplOptions} || {} },
        %{ $args->{TmplOptions} || {} },
    };

    my $include_path
        = delete $options->{INCLUDE_PATH}
        || $c->view->config->{INCLUDE_PATH}
        || [ $c->config->{root}, $c->config->{root} . '/base' ];

    if ( $c->config->{ForceUTF8} or $c->config->{email}{ForceUTF8} || $args->{ForceUTF8} ) {
        $_->require
            || Catalyst::Exception->throw( message => $! )
            for qw/Template::Provider::Encoding Template::Stash::ForceUTF8/;
        $options->{LOAD_TEMPLATES} = [ Template::Provider::Encoding->new( INCLUDE_PATH => $include_path ) ];
        $options->{STASH} = Template::Stash::ForceUTF8->new;
    }
    else {
        $options->{INCLUDE_PATH} = $include_path;
    }

    my $params = {
        base => $c->req->base,
        c => $c,
        name => $c->config->{name},
        %{ $c->stash },
        %{ $args->{TmplParams} || {} },
    };

    my $msg = $module->new(
        %{$c->config->{email} || {} },
        %{$args || {} },
        Template => $template,
        TmplParams => $params,
        TmplOptions => $options,
        Icode => $args->{Icode} || $c->config->{email}->{Icode} || 'utf8',
        LineWidth => $args->{LineWidth} || $c->config->{email}->{LineWidth} || 0,
    );

    my $route = $c->config->{email}->{mailroute} || { via => 'smtp', host => 'localhost' };
    $route->{via} ||= 'smtp';

    eval {
        if ( $route->{via} eq 'smtp_tls' ) {
            $msg->send_by_smtp_tls(
                $route->{host},
                User     => $route->{username},
                Password => $route->{password},
                Port     => $route->{port} || 587,
            );
        }
        elsif ( $route->{via} eq 'sendmail' ) {
            my %param;
            $param{FromSender} = '<' . $c->config->{email}->{mailfrom} . '>' if $c->config->{email}->{mailfrom};
            $param{Sendmail} = $route->{command} if defined $route->{command};
            $msg->send( 'sendmail', %param );
        }
        else {
            my @args = $route->{host} ? ( $route->{host} ) : ();
            $msg->send( $route->{via}, @args );
        }
    };

    if ($@) {
        Catalyst::Exception->throw( message => "Error while sending emails: $@" )
    }

    1;
}

1;