GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  MOJOLICIOUS::PLUGIN::MAIL (3)

.ds Aq ’

NAME

Mojolicious::Plugin::Mail - Mojolicious Plugin for send mail

CONTENTS

SYNOPSIS



  # Mojolicious::Lite
  plugin mail;

  # Mojolicious with config
  $self->plugin(mail => {
    from => sharifulin@gmail.com,
    type => text/html,
  });

  # in controller
  $self->mail(
    to      => sharifulin@gmail.com,
    subject => Test,
    data    => use Perl or die;,
  );

  # in controller, using render
  $self->mail(to => sharifulin@gmail.com, template => controller/action, format => mail);

  # template: controller/action.mail.ep
  % stash subject => Test;
  use Perl or die;



DESCRIPTION

Mojolicous::Plugin::Mail is a plugin for Mojolicious apps to send mail using MIME::Lite.

HELPERS

Mojolicious::Plugin::Mail contains two helpers: mail and render_mail.

CWmail



  # simple interface
  $self->mail(
      to       => sharifulin@gmail.com,
      from     => sharifulin@gmail.com,
     
      reply_to => reply_to+sharifulin@gmail.com,
     
      cc       => ..,
      bcc      => ..,
     
      type     => text/plain,

      subject  => Test,
      data     => use Perl or die;,
  );

  # interface as MIME::Lite
  $self->mail(
      # test mode
      test   => 1,
     
      # as MIME::Lite->new( ... )
      mail   => {
        To       => sharifulin@gmail.com,
        Subject  => Test,
        Data     => use Perl or die;,
       
        # add credentials parameters
        AuthUser => username,
        AuthPass => password,
      },

      attach => [
        # as MIME::Lite->attach( .. )
        { ... },
        ...
      },

      headers => [
        # as MIME::Lite->add( .. )
        { ... },
        ...
      },

      attr => [
        # as MIME::Lite->attr( .. )
        { ... },
        ...
      },
  );



Build and send email, return mail as string.

Supported parameters:
o to

Header ’To’ of mail.

o from

Header ’From’ of mail.

o reply_to

Header ’Reply-To’ of mail.

o cc

Header ’Cc’ of mail.

o bcc

Header ’Bcc’ of mail.

o type

Content type of mail, default is conf’s type.

o subject

Header ’Subject’ of mail.

o data

Content of mail

o mail

Hashref, containts parameters as new(PARAMHASH). See MIME::Lite.

o attach

Arrayref of hashref, hashref containts parameters as attach(PARAMHASH). See MIME::Lite.

o headers

Arrayref of hashref, hashref containts parameters as add(TAG, VALUE). See MIME::Lite.

o attr

Arrayref of hashref, hashref containts parameters as attr(ATTR, VALUE). See MIME::Lite.

o test

Test mode, don’t send mail.

o charset

Charset of mail, default charset is UTF-8.

o mimeword

Using mimeword or not, default value is 1.

o nomailer

No using ’X-Mailer’ header of mail, default value is 1.

If no subject, uses value of stash parameter ’subject’.

If no data, call render_mail helper with all stash parameters.

CWrender_mail



  my $data = $self->render_mail(user/signup);

  # or use stash params
  my $data = $self->render_mail(template => user/signup, user => $user);



Render mail template and return data, mail template format is mail, i.e. user/signup.mail.ep.

ATTRIBUTES

Mojolicious::Plugin::Mail contains one attribute - conf.

CWconf



  $plugin->conf;



Config of mail plugin, hashref.

Keys of conf:
o from

From address, default value is test-mail-plugin@mojolicio.us.

o encoding

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> Default value is base64.

o charset

Default charset of Subject and any Data, default value is UTF-8.

o type

Default type of Data, default value is text/plain.

o how

HOW parameter of MIME::Lite::send: sendmail or smtp.

o howargs

HOWARGS parameter of MIME::Lite::send (arrayref).



  my $conf = {
    from     => sharifulin@gmail.com,
    encoding => base64,
    type     => text/html,
    how      => sendmail,
    howargs  => [ /usr/sbin/sendmail -t ],
  };

  # in Mojolicious app
  $self->plugin(mail => $conf);
 
  # in Mojolicious::Lite app
  plugin mail => $conf;



METHODS

Mojolicious::Plugin::Mail inherits all methods from Mojolicious::Plugin and implements the following new ones.

CWregister



  $plugin->register($app, $conf);



Register plugin hooks in Mojolicious application.

CWbuild



  $plugin->build( mail => { ... }, ... );



Build mail using MIME::Lite and MIME::EncWords and return MIME::Lite object.

TEST MODE

Mojolicious::Plugin::Mail has test mode, no send mail.



  # all mail dont send mail
  BEGIN { $ENV{MOJO_MAIL_TEST} = 1 };

  # or only once
  $self->mail(
    test => 1,
    to   => ...,
  );



EXAMPLES

The Mojolicious::Lite example you can see in example/test.pl.

Simple interface for send plain mail:



  get /simple => sub {
    my $self = shift;
   
    $self->mail(
      to      => sharifulin@gmail.com,
      type    => text/plain,
      subject => XXXX XXXXXX,
      data    => XXXXXX!,
    );
  };



Simple send mail:



  get /simple => sub {
    my $self = shift;
   
    $self->mail(
      mail => {
        To      => sharifulin@gmail.com,
        Subject => XXXX XXXXXX,
        Data    => "<p>XXXXXX!</p>",
      },
    );
  };



Simple send mail with test mode:



  get /simple2 => sub {
    my $self = shift;
   
    my $mail = $self->mail(
      test => 1,
      mail => {
        To      => "XXXXXXXX XXXXXXXXX" sharifulin@gmail.com,
        Cc      => "XXXXXXXX XXXXXXXXX" <sharifulin@gmail.com>, Anatoly Sharifulin sharifulin@gmail.com,
        Bcc     => sharifulin@gmail.com,
        Subject => XXXX XXXXXX,
        Type    => text/plain,
        Data    => "<p>XXXXXX!</p>",
      },
    );
   
    warn $mail;
  };



Mail with binary attachcment, charset is windows-1251, mimewords off and mail has custom header:



  get /attach => sub {
    my $self = shift;
   
    my $mail = $self->mail(
      charset  => windows-1251,
      mimeword => 0,

      mail => {
        To      => sharifulin@gmail.com,
        Subject => Test attach,
        Type    => multipart/mixed
      },
      attach => [
        {
          Data => Any data,
        },
        {
          Type        => BINARY,
          Filename    => crash.data,
          Disposition => attachment,
          Data        => binary data binary data binary data binary data binary data,
        },
      ],
      headers => [ { X-My-Header => Mojolicious } ],
    );
  };



Multipart mixed mail:



  get /multi => sub {
    my $self = shift;
   
    $self->mail(
      mail => {
        To      => sharifulin@gmail.com,
        Subject => XXXXXX,
        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"
        },
      ],
    );
  };



Render mail using simple interface and Reply-To header:



  get /render_simple => sub {
    my $self = shift;
    my $mail = $self->mail(to => sharifulin@gmail.com, reply_to => reply_to+sharifulin@gmail.com);

    $self->render(ok => 1, mail => $mail);
} => render;



Mail with render data and subject from stash param:



  get /render => sub {
    my $self = shift;

    my $data = $self->render_mail(render);
    $self->mail(
      mail => {
        To      => sharifulin@gmail.com,
        Subject => $self->stash(subject),
        Data    => $data,
      },
    );
  } => render;

  __DATA__

  @@ render.html.ep
  <p>Hello render!</p>
 
  @@ render.mail.ep
  % stash subject => XXXXXX render;
 
  <p>XXXXXX mail render!</p>



Send email via remote SMTP server.



  # in main
  $self->plugin(
    mail => {
      from    => info@host.example,
      type    => text/html,
      how     => smtp,
      howargs => [ mail.host.example,
                      AuthUser => me@host.example,
                      AuthPass => 123xyz,
                 ],
    }
  );
 
  # in controller
  $self->mail(
    to      => friend@hishost.example,
    subject => Test,
    data    => use Perl or die;,
  );



SEE ALSO

MIME::Lite MIME::EncWords Mojolicious Mojolicious::Guides <http://mojolicious.org>.

AUTHOR

Anatoly Sharifulin <sharifulin@gmail.com>

THANKS

Alex Kapranoff <kapranoff@gmail.com>

BUGS

Please report any bugs or feature requests to bug-mojolicious-plugin-mail at rt.cpan.org, or through the web interface at <http://rt.cpan.org/NoAuth/ReportBug.htMail?Queue=Mojolicious-Plugin-Mail>. We will be notified, and then you’ll automatically be notified of progress on your bug as we make changes.
o Github

<http://github.com/sharifulin/mojolicious-plugin-mail/tree/master>

o RT: CPAN’s request tracker

<http://rt.cpan.org/NoAuth/Bugs.htMail?Dist=Mojolicious-Plugin-Mail>

o AnnoCPAN: Annotated CPAN documentation

<http://annocpan.org/dist/Mojolicious-Plugin-Mail>

o CPANTS: CPAN Testing Service

<http://cpants.perl.org/dist/overview/Mojolicious-Plugin-Mail>

o CPAN Ratings

<http://cpanratings.perl.org/d/Mojolicious-Plugin-Mail>

o Search CPAN

<http://search.cpan.org/dist/Mojolicious-Plugin-Mail>

COPYRIGHT & LICENSE

Copyright (C) 2010-2013 by Anatoly Sharifulin.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 MOJOLICIOUS::PLUGIN::MAIL (3) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.