NAME
MojoX::Renderer::Mail - Mail renderer for Mojo and Mojolicious.
Uses MIME::Lite and MIME::EncWords.
All headers such as From, To, Cc, Bcc and Subject are encoded words.
SYNOPSIS
#!/usr/bin/perl
use utf8;
use Mojolicious::Lite;
use MojoX::Renderer::Mail;
app->renderer->add_handler(
mail => MojoX::Renderer::Mail->build(
from => 'sharifulin@gmail.com',
encoding => 'base64',
how => 'sendmail',
howargs => [ '/usr/sbin/sendmail -t' ],
),
);
Simple mail example:
get '/simple' => sub {
my $self = shift;
$self->render(
handler => 'mail',
mail => {
To => '"Анатолий Шарифулин" sharifulin@gmail.com',
Cc => '"Анатолий Шарифулин" <sharifulin@gmail.com>, Anatoly Sharifulin sharifulin@gmail.com',
Bcc => 'sharifulin@gmail.com',
Subject => 'Тест письмо',
Type => 'text/html',
Data => "<p>Привет!</p>",
},
);
$self->render_text('OK');
};
Attachment mail example:
get '/attach' => sub {
my $self = shift;
$self->render(
handler => 'mail',
# charset => '...',
# mimeword => 0,
mail => {
To => 'sharifulin@gmail.com',
Subject => 'Тест аттач',
Type => 'multipart/mixed'
},
attach => [
{
Data => 'Текст письма',
},
{
Type => 'BINARY',
Filename => 'crash.data',
Disposition => 'attachment',
Data => 'binary data binary data binary data binary data binary data',
},
],
headers => [ { 'X-My-Header' => 'Mojolicious' } ],
);
$self->render_text('OK');
};
Multipart mixed mail example:
get '/multi' => sub {
my $self = shift;
$self->render(
handler => 'mail',
mail => {
To => 'sharifulin@gmail.com',
Subject => 'Мульти',
Type => 'multipart/mixed'
},
attach => [
{
Type => 'TEXT',
Encoding => '7bit',
Data => "Just a quick note to say hi!"
},
{
Type => 'image/gif',
Path => $0
},
{
Type => 'x-gzip',
Path => "gzip < $0 |",
ReadNow => 1,
Filename => "somefile.zip"
},
],
);
$self->render_text('OK');
};
Render mail example:
get '/render' => sub {
my $self = shift;
$self->render(
handler => 'mail',
mail => {
To => 'sharifulin@gmail.com',
Subject => 'Тест render',
Type => 'text/html',
Data => $self->render_partial('render', format => 'mail'),
},
);
$self->render(format => 'html');
} => 'render';
get '/render2' => sub {
my $self = shift;
my $data = $self->render_partial('render2', format => 'mail');
$self->render(
handler => 'mail',
mail => {
To => 'sharifulin@gmail.com',
Subject => $self->stash('subject'),
Type => 'text/html',
Data => $data,
},
);
$self->render(template => 'render', format => 'html');
} => 'render';
app->start;
__DATA__
@@ render.html.ep
<p>Привет render!</p>
@@ render.mail.ep
<p>Привет васса render!</p>
@@ render2.mail.ep
% stash 'subject' => 'Привет render2';
<p>Привет васса render2!</p>
METHODS
build
This method returns a handler for the Mojo renderer.
Supported parameters:
from
Default from address
encoding
Default encoding of Subject and any Data, value is MIME::Lite content transfer encoding http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm#Content_transfer_encodings
charset
Default charset of Subject and any Data, default value is UTF-8
how
HOW parameter of MIME::Lite::send, value are sendmail or smtp
howargs
HOWARGS parameter of MIME::Lite::send (arrayref)
RENDER
$self->render(
handler => 'mail',
mail => { ... }, # as MIME::Lite->new( ... )
attach => [
{ ... }, # as MIME::Lite->attach( .. )
...
},
headers => [
{ ... }, # as MIME::Lite->add( .. )
...
},
attr => [
{ ... }, # as MIME::Lite->attr( .. )
...
},
);
Supported parameters:
mail
Hashref, containts parameters as new(PARAMHASH). See MIME::Lite http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm#Construction.
attach
Arrayref of hashref, hashref containts parameters as attach(PARAMHASH). See MIME::Lite http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm#Construction.
headers
Arrayref of hashref, hashref containts parameters as add(TAG, VALUE). See MIME::Lite http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm#Construction.
attr
Arrayref of hashref, hashref containts parameters as attr(ATTR, VALUE). See MIME::Lite http://search.cpan.org/~rjbs/MIME-Lite-3.027/lib/MIME/Lite.pm#Construction.
ENVIROMENT VARIABLES
Module has two env variables:
DEBUG
Print mail, default value is 0
TEST
No send mail, default value is 0
TEST AND RUN
TEST=1 DEBUG=1 PATH_INFO='/multi' script/test cgi
SEE ALSO
AUTHOR
Anatoly Sharifulin <sharifulin@gmail.com>
THANKS
Alex Kapranoff <kapranoff@gmail.com>
BUGS
Please report any bugs or feature requests to bug-acme-cpanauthors-russian at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=MojoX-Renderer-Mail. We will be notified, and then you'll automatically be notified of progress on your bug as we make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MojoX::Renderer::Mail
You can also look for information at:
Github
http://github.com/sharifulin/MojoX-Renderer-Mail/tree/master
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.htMail?Dist=MojoX-Renderer-Mail
AnnoCPAN: Annotated CPAN documentation
CPANTS: CPAN Testing Service
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright (C) 2010 by Anatoly Sharifulin.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.