[Catalyst-dev] Catalyst plugin

Octavian Rasnita orasnita at gmail.com
Tue Sep 30 07:31:35 BST 2008


Hi,

I've created a Catalyst plugin and I want to upload it to CPAN. Please tell me if it is well to use it as a plugin, or if the suggested name is right.
(It is my first perl module that I want to upload to CPAN.)

I like to send email from Catalyst apps using
$c->email

but the problem with this approach (or many others) is that it is hard to send emails that are UTF-8 encoded, that have a text and an html part, that have one or more attachments, images inline, because I must know more about MIME types and create each part separately specifying the MIME type, the Content-Type, etc.

So I've made a plugin that uses the module Mail::Builder to create the message and Email::Send to send it.
The suggested name would be Catalyst::Plugin::Mail.

I think it could be a plugin, just as C::P::Email, because I think the most easy would be to use it just as C::P::Email, but if you have other suggestions, please tell me.

The interface of this module should be something like:

in MyApp.pm

__PACKAGE__->config(
  'mail' => {
    mailer_args => ['SMTP', Host => 'smtp.mymail.com'],
    #mailer_args => ['Gmail', username => 'user', password => 'pass'],
    #mailer_args => ['Sendmail'],
    #... other senders supported by Email::Send
    mail_args => {
      from => 'me at mymail.com',
      #from => ['me at mymail.com', 'My Real Name'],
      #... and other mail fields like To:, Cc:, Subject:, if wanted
    },
  },
);

in a controller:

$c->mail(
  to => 'you at yourmail.com',
  subject => 'The subject (with UTF-8 chars)',
  htmltext => '<h1>Hello</h1> world (also UTF-8 encoded)',
);

or:

$c->mail(
  from => ['me at mymail.com', 'My Name'],
  to => ['you at yourmail.com', 'Your Name'],
  subject => 'The subject',
  plaintext => 'The plain text',
  htmltext => 'The HTML text',
  attachment => ['file1.pdf', 'file2.pdf'],
  image => ['image1.png', 'image2.png'],
);

or:

$c->mail(
  more_to => [
    'friend1 at mail.com',
    'friend2 at mail.com',
    ['friend3 at mail.com', 'Name of Friend3'],
  ],
  subject => 'The subject',
  htmltext => 'The html text',
);

or:

$c->mail(
  mailer_args => ['SMTP', Host => 'mail.another.com'],
  from => 'me at another.com',
  to => 'you at yourmail.com',
  subject => 'The subject',
  plaintext => 'Text...',
);

Thank you.

Octavian




More information about the Catalyst-dev mailing list