NAME

MojoX::Renderer::Mail - Mail renderer for Mojo and Mojolicious.

Uses MIME::Lite and MIME::EncWords.

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' ],
    ),
  );

  get '/simple' => sub {
    my $self = shift;
    
    $self->render(
      handler => 'mail',
      
      mail => {
        To      => '"Анатолий Шарифулин" sharifulin@gmail.com',
        Cc      => '"Анатолий Шарифулин" <sharifulin@gmail.com>, Anatoly Sharifulin sharifulin@gmail.com, Анатолий2 Шарифулин2 sharifulin@gmail.com',
        Bcc     => 'sharifulin@gmail.com',
        Subject => 'Тест письмо',
        Type    => 'text/html',
        Data    => "<p>Привет!</p>",
      },
    );
    
    $self->render_text('OK');
  };

  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');
  };

  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');
  };

  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>


INSTALLATION

To install this module, run the following commands:

	perl Build.PL
	./Build
	./Build test
	./Build install

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the
perldoc command.

    perldoc MojoX::Renderer::Mail

You can also look for information at:

    RT, CPAN's request tracker
        http://rt.cpan.org/NoAuth/Bugs.html?Dist=MojoX-Renderer-Mail

    AnnoCPAN, Annotated CPAN documentation
        http://annocpan.org/dist/MojoX-Renderer-Mail

    CPAN Ratings
        http://cpanratings.perl.org/d/MojoX-Renderer-Mail

    Search CPAN
        http://search.cpan.org/dist/MojoX-Renderer-Mail/


LICENSE AND COPYRIGHT

Copyright (C) 2010 Anatoly Sharifulin

This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

