Re: [Catalyst] Catalyst::Plugin::Email, TT, html config problem

2012-12-18 Thread Nick Anderson


Hi Tadhg,

Shouldn't it be just:

content_type = 'text/html' ?


Nick

On 18/12/12 20:36, Tadhg wrote:


Hi,

I can't get SMTP email messages to use HTML encoding using 
Catalyst::Plugin::Email and TT. The mails are being generated and 
contain the html tags from the correct template and correct stashed 
data, but it's being displayed as plain text in the received email.


It's a simple logging application, allowing various distributed 
scripts to log messages centrally. When an error message is logged I 
want to generate a mail to the appropriate admin.


I'm assuming the content_type_set = 'text/html' line is wrong but 
can't find what it should be.



Any help would be appriciated, code extracts etc. are below.



*App Config:*

use Catalyst qw/

-Debug

ConfigLoader

Static::Simple

AutoCRUD

Email

StackTrace

/;

*Mail Code:*

...

$c-stash(add_log_line = $add_log_line,

template = 'log/add_general.tt http://add_general.tt');

$c-forward($c-view('HTML'));

$c-email(

header = [

From = 'b...@bob.com mailto:b...@bob.com',

To = 'f...@bob.com mailto:f...@bob.com',

Subject = 'An error has been reported'

],

body = $c-view('HTML')-render($c,'log/email_msg.tt 
http://email_msg.tt'),


content_type_set = 'text/html'

);

*Received Mail:*

!DOCTYPE

body

table

tr

thmsg_type/th

thmessage/th

thsource_hostname/th

...

Thanks,

Tadhg Daley



___
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/


___
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/


Re: [Catalyst] Catalyst::Plugin::Email, TT, html config problem

2012-12-18 Thread 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


On Tue, Dec 18, 2012 at 9:36 PM, Tadhg tadhg.da...@gmail.com wrote:

 Hi,

 ** **

 I can’t get SMTP email messages to use HTML encoding using
 Catalyst::Plugin::Email and TT. The mails are being generated and contain
 the html tags from the correct template and correct stashed data, but it’s
 being displayed as plain text in the received email.

 ** **

 It’s a simple logging application, allowing various distributed scripts to
 log messages centrally. When an error message is logged I want to generate
 a mail to the appropriate admin.



 I'm assuming the content_type_set = 'text/html' line is wrong but
 can't find what it should be.


 Any help would be appriciated, code extracts etc. are below.



 **

 *App Config:*

 use Catalyst qw/

 -Debug

 ConfigLoader

 Static::Simple

 AutoCRUD

 Email

 

 StackTrace

 /;

 ** **

 *Mail Code:*

 …

 $c-stash(add_log_line = $add_log_line,

 template = 'log/add_general.tt');  

 $c-forward($c-view('HTML'));

   

 $c-email(

 header = [

 From= 'b...@bob.com',

 To  = 'f...@bob.com',

 Subject = 'An error has been reported'

 ],

 body = $c-view('HTML')-render($c,'log/email_msg.tt'),

 content_type_set = 'text/html'

 );

 ** **

 *Received Mail:*

 !DOCTYPE

 body

 table

 tr

 thmsg_type/th

 thmessage/th

 thsource_hostname/th

 …

 

 ** **

 Thanks,

 Tadhg Daley

 ___
 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/


___
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/


Re: [Catalyst] Catalyst::Plugin::Email, TT, html config problem

2012-12-18 Thread Octavian Rasnita
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/