[Catalyst] Sending email from Catalyst and scripts

Evaldas Imbrasas evaldas at imbrasas.com
Wed May 23 00:02:27 GMT 2007


J,

I've looked at your module, but I'm afraid it would actually make
sending emails even more dependent on catalyst, and I want to be able
to use the same email framework from both catalyst and command-line
scripts.

In my setup, each email belongs to one emailclass. Metadata for each
emailclass, including template_name, is stored in the database.
template_name defines the location for the template files for this
email class. A list of template files usually consists of templates
for text version, HTML version, email subject, and email headers (all
of them are TT templates). Each email class also has its own test
script which sends a sample email for that class.

I have two TT views - one for the text emails, and another for HTML
emails (each view has its own wrappers). As I've mentioned before,
send_email method in Controller::Email does the bulk of work: based on
the emailclass, it fetches the template files and uses the TT views to
render the parts of the email, which is then contructed using
Email::MIME::Creator (although I could have used
Catalyst::Plugin::Email as well), stores metadata for this email into
database, and then actually sends it.

So, to rephrase, my question is actually not about how to send email
from catalyst - the above setup works really well. I just want to be
able to use the same method to send emails from catalyst AND
command-line scripts. I see two ways to consider (there might be
more):

1) Somehow setup the catalyst context $c in the command-line scripts,
so I could call the same send_email method from Controller::Email. Is
this possible?

2) Move the bulk of send_email out of catalyst and just leave a
wrapper for that method in Controller::Email. The problem would be
that catalyst provides many helpful methods (i.e., easy access to
preconfigured views and models), and those wouldn't be available
outside of catalyst.


On 5/22/07, J. Shirley <jshirley at gmail.com> wrote:
> I've recently been working on an Email view, which I hope will become the
> recommended way to send Email from Catalyst.  It hitches into Email::Send,
> and also ties into your Template view (which, sadly, only works with
> View::TT at the moment but I'm hoping to get the other views supported soon)
>
> I haven't posted it to CPAN yet, as I'm waiting to get some tests written up
> for it, but you can download it from the Catalyst SVN repository at:
> http://dev.catalystframework.org/repos/Catalyst/trunk/Catalyst-View-Email/
>
> I also have a tarball at
> http://staff.toeat.com/~jshirley/Catalyst-View-Email-0.01.tar.gz
>
> I recommend you read through the pod for both Catalyst::View::Email and
> Catalyst::View::Email::Template
>
> And, as for sending out an email via the command line, there are many ways
> to achieve this depending upon what your goal and full use case is.
>
> Good luck, and happy hacking,
> -J

-- 
-----------------------------------------------------
Evaldas Imbrasas
http://www.imbrasas.com



More information about the Catalyst mailing list