[Catalyst] Sending email from a Catalyst app

Octavian Rasnita orasnita at gmail.com
Wed Jul 2 12:59:56 BST 2008


From: "ivorw" <m9tn-oh4c at xemaps.com>
>I know there's more than one way to do this. I'm looking at what the
> best practice is.
> 
> I've had some success inthe past with Catalyst::Plugin::Email, but I'm
> now looking at Catalyst::View::Email[::Template] which seems altogether
> much cleaner, able to be controlled from the config.
> 

A more cleaner and better solution is to use Mail::Sender::Easy.

You can create UTF-8 encoded messages, include attachments, inline images, create messages with a text and an html part, and if you use MIME::Words you can also use special chars in To, From and Subject fields or other headers.

You can do:

use Mail::Sender::Easy qw(email);
use MIME::Words qw(:all);

email({
fromaddr => 'me at site.com',
from => 'My Name <me at site.com>',
toaddr => 'you at site.eu',
to => encode_mimewords('Your Name with special chars <you at site.eu>', Charset => "UTF-8"),
subject => 'The subject',
smtp => '127.0.0.1',

#auth => 'LOGIN',
#authid => "user",
#authpwd => "password",
#skip_bad_recipients => 1,

_text => 'The text body',
_html => 'The <b>html</b> body',
_text_info => {charset => "UTF-8"},
_html_info => {charset => "UTF-8"},

#priority => 2, # 1-5 high to low
#confirm => 'delivery, reading',

_attachments => {
  'smiley.gif' => {
    _disptype => 'GIF Image',
    _inline => 'smile1',
    description => 'Smiley',
    ctype => 'image/gif',    
    file => '/home/foo/images/smiley.gif',
  },
  'mydata.pdf' => {
    description => 'Data Sheet',  
    ctype => 'application/pdf',
    msg => 'message',
  },
},
}) or die $@;

It would be also nice a Catalyst::Plugin::Mail or Catalyst::View::Mail that uses Mail::Sender::Easy and MIME::Words, but using those modules directly is very easy and doesn't require writing much code anyway.

And of course, Mail::Sender::Easy offers much many options than those shown.

Octavian




More information about the Catalyst mailing list