From: Dimitar Petrov 

  Hello Thag,


  I think plugin is the wrong approach here. Plugins seemed to be good idea in 
the past, but now they are recommended only if you mess with the internals.
  I think the recommended think to send emails within Catalyst application is 
either:


  a) https://metacpan.org/module/Catalyst::View::Email or 
https://metacpan.org/module/Catalyst::View::Email::Template
  b) create a separe model, like shown here 
http://modernperlbooks.com/mt/2012/07/extracting-a-reusable-catalyst-model.html


  Cheers,
  Dimitar



  As Chromatic said in that article in modernperlbooks.com, it is a good idea 
to create a standalone script that can send email because it can work in 
Catalyst apps, and can also work in standalone scripts ran manually or by cron 
jobs. It can also work with job queues.

  The module from that article uses Mail::Builder::Simple which can be simply 
used with something like:

       use Mail::Builder::Simple;

       my $mail = Mail::Builder::Simple->new;

       $mail->send(
        from => 'm...@host.com',
        to => 'y...@yourhost.com',
        subject => 'The subject with UTF-8 chars',
        plaintext => "Hello,\n\nHow are you?\n",
       );

  Mail::Builder::Simple sets the MIME headers automaticly and also encodes the 
MIME headers and the HTML and text body of the messages to UTF-8.

  If you know that you'll never want to send email with a program outside the 
Catalyst app, you can use Mail::Builder::Simple easier by installing
  Catalyst::Helper::Model::Email
  and create a model for sending email with it, using something like:

   ./script/myapp_create.pl model MyMailer Email SMTP smtp.host.com usr passwd

  And then you can send email with it using something like:

   $c->model("MyMailer"->send(
     from => 'm...@host.com',
     to => 'y...@yourhost.com',
     subject => 'The subject with UTF-8 chars',
     plaintext => "Hello\n\nHow are you?\n\n",
   );

  For more info:

  https://metacpan.org/module/Catalyst::Helper::Model::Email

  and

  https://metacpan.org/module/Mail::Builder::Simple

  Octavian
_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to