Re: [cgiapp] Best email module?

2009-02-01 Thread Octavian Rasnita

Hi,

That long code also uses XS and you could do it shorter using something 
like:


use Mail::Builder::Simple;
use File::Spec::Functions qw/catdir/;

my $mail = Mail::Builder::Simple-new(
 from = ['do-not-re...@example.com', 'example.com'],
 reply = 'reply...@example.com',
 subject = 'The subject',
 htmltext = ['template.tmpl', ':TT'],
 plaintext = ['text_template.tmpl', ':TT'],
 sender = 'WordPine::Email',
 template_args = {
   COMPILE_DIR = catdir($ENV{APP_ROOT}, 'tmp'),
   INCLUDE_PATH = catdir($ENV{APP_ROOT}, 'templates'),
   COMPILE_EXT = '.ttc',
 },
);

foreach my $email(@emails) {
 $mail-send(to = $email);
}

The headers and the body are automaticly encoded to UTF-8, you can also add 
attachments and inline images easy and you can also use other templating 
systems than Template-Toolkit, like HTML::Template for creating the body 
parts or the attachments.


Octavian

- Original Message - 
From: James.Q.L shijial...@yahoo.com

To: CGI Application cgiapp@lists.erlbaum.net
Sent: Sunday, February 01, 2009 8:22 AM
Subject: Re: [cgiapp] Best email module?



--- Lyle webmas...@cosmicperl.com wrote:


Michael Peters wrote:
 Stewart Heckenberg wrote:
 I like MIME::Lite -- has a very simple attachment interface :)

 MIME::Lite is what I've used in the past, although the Perl Email
 folks don't recommend it. Apparently it's very crufty on the insides.
 I think they recommend Email::MIME instead.

Email::MIME looks good, but Email::Stuff seems like an easier interface
to it.

I notice that Email::Send now says to use Email::Sender instead. Anyone
got any experience with this?



I used it a while ago. It did took me some time and some sample codes to 
figure out how to use
bunch of Email::* modules to do what I want. I hope the code speak for 
itself. :)


use Email::Address;
use Email::MessageID;
use Email::Send;
use Email::Simple;
#use Email::MIME::CreateHTML;
use Email::MIME::Creator;
use Encode qw( encode );
use Template;
use HTML::FormatText::WithLinks;
use File::Spec::Functions qw/catdir/;
use Carp;


$Email::Send::Sendmail::SENDMAIL = '/usr/sbin/sendmail';
my $Sender = Email::Send-new( { mailer = 'Sendmail' } );
my $from_address = Email::Address-new( 'example.com', 
'do-not-re...@example.com' )-format();


our $TEMPLATE = Template-new(
   COMPILE_DIR  = catdir( $ENV{APP_ROOT}, 'tmp' ),
   INCLUDE_PATH = catdir( $ENV{APP_ROOT}, 'templates' ),
   COMPILE_EXT  = '.ttc',
);

sub send_email {
   my $class = shift;
   my $p = shift;

die unless defined $p-{to};
die unless defined $p-{subject};
die unless defined $p-{template};
die unless defined $p-{params};

   my $html_body = _htmlBody( $p );
   my $text_body = _textBody( $html_body );

   # multipart message
   # put the best alternative at the last.
   my @parts = (
 Email::MIME-create(
 attributes = {
 content_type = text/plain,
#  disposition  = attachment,
 charset  = UTF-8,
 },
 body = encode( 'utf8', $text_body ),
 ),
 Email::MIME-create(
 attributes = {
 content_type = text/html,
#  disposition  = attachment,
 charset  = UTF-8,
 },
 body = encode( 'utf8', $html_body ),
 ),
   );

   my %headers =
   ( From = $p-{from} || $from_address,
 'Reply-To'   = $p-{from} || $from_address,
 To   = $p-{to},
 Subject  = $p-{subject},
 'Message-ID' = q{} . Email::MessageID-new() . q{},
 'Content-Transfer-Encoding' = '7bit',
 'X-Sender'  = 'WordPine::Email',
   );
   # for sending html/plain alternatives email:
   #need three Email::MIME objects.
   #One is the top-level multi/aalt part.
   #the other two are the html/plain alternatives
   my $email = Email::MIME-create(
 header = [ %headers ],
 parts  = [ @parts ],
 attributes = { content_type = 'multipart/alternative', },
   );

   my $rv = $Sender-send( $email );
   warn $rv unless $rv;
}

sub _htmlBody {
   my $p = shift;
   my $tmpl_file = Email/.  $p-{template} . .tmpl;
   my $html;
   $TEMPLATE-process( $tmpl_file, $p-{params}, \$html ) || croak 
$TEMPLATE-error();

   return $html;
}

sub _textBody {
   my $html = shift;
   return HTML::FormatText::WithLinks-new()-parse($html);
}

1;


Qiang(James)




#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####





#  CGI::Application

Re: [cgiapp] Best email module?

2009-01-31 Thread James.Q.L
--- Lyle webmas...@cosmicperl.com wrote:

 Michael Peters wrote:
  Stewart Heckenberg wrote:
  I like MIME::Lite -- has a very simple attachment interface :)
 
  MIME::Lite is what I've used in the past, although the Perl Email 
  folks don't recommend it. Apparently it's very crufty on the insides. 
  I think they recommend Email::MIME instead.
 
 Email::MIME looks good, but Email::Stuff seems like an easier interface 
 to it.
 
 I notice that Email::Send now says to use Email::Sender instead. Anyone 
 got any experience with this?
 

I used it a while ago. It did took me some time and some sample codes to figure 
out how to use
bunch of Email::* modules to do what I want. I hope the code speak for itself. 
:)

use Email::Address;
use Email::MessageID;
use Email::Send;
use Email::Simple;
#use Email::MIME::CreateHTML;
use Email::MIME::Creator;
use Encode qw( encode );
use Template;
use HTML::FormatText::WithLinks;
use File::Spec::Functions qw/catdir/;
use Carp;


$Email::Send::Sendmail::SENDMAIL = '/usr/sbin/sendmail';
my $Sender = Email::Send-new( { mailer = 'Sendmail' } );
my $from_address = Email::Address-new( 'example.com', 
'do-not-re...@example.com' )-format();

our $TEMPLATE = Template-new(
COMPILE_DIR  = catdir( $ENV{APP_ROOT}, 'tmp' ),
INCLUDE_PATH = catdir( $ENV{APP_ROOT}, 'templates' ),
COMPILE_EXT  = '.ttc',
);

sub send_email {
my $class = shift;
my $p = shift;

die unless defined $p-{to};
die unless defined $p-{subject};
die unless defined $p-{template};
die unless defined $p-{params};

my $html_body = _htmlBody( $p );
my $text_body = _textBody( $html_body );

# multipart message
# put the best alternative at the last.
my @parts = (
  Email::MIME-create(
  attributes = {
  content_type = text/plain,
#  disposition  = attachment,
  charset  = UTF-8,
  },
  body = encode( 'utf8', $text_body ),
  ),
  Email::MIME-create(
  attributes = {
  content_type = text/html,
#  disposition  = attachment,
  charset  = UTF-8,
  },
  body = encode( 'utf8', $html_body ),
  ),
);

my %headers =
( From = $p-{from} || $from_address,
  'Reply-To'   = $p-{from} || $from_address,
  To   = $p-{to},
  Subject  = $p-{subject},
  'Message-ID' = q{} . Email::MessageID-new() . q{},
  'Content-Transfer-Encoding' = '7bit',
  'X-Sender'  = 'WordPine::Email',
);
# for sending html/plain alternatives email:
#need three Email::MIME objects.
#One is the top-level multi/aalt part.
#the other two are the html/plain alternatives
my $email = Email::MIME-create(
  header = [ %headers ],
  parts  = [ @parts ],
  attributes = { content_type = 'multipart/alternative', },
);

my $rv = $Sender-send( $email );
warn $rv unless $rv;
}

sub _htmlBody {
my $p = shift;
my $tmpl_file = Email/.  $p-{template} . .tmpl;
my $html;
$TEMPLATE-process( $tmpl_file, $p-{params}, \$html ) || croak 
$TEMPLATE-error();
return $html;
}

sub _textBody {
my $html = shift;
return HTML::FormatText::WithLinks-new()-parse($html);
}

1;


Qiang(James)


  

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Joshua Miller
I've gotta second (or third) MIME::Lite - very nice interface, and
works like a charm.

On Thu, Jan 29, 2009 at 10:45 PM, Lyle webmas...@cosmicperl.com wrote:
 Peter Karman wrote:

 Lyle wrote on 1/29/09 8:26 PM:


 Hi All,
  I wondering what peoples experiences are with email modules on CPAN.

 ...

 Any recommendations? Maybe a C::A::P wrapper around the best one(s)
 would be good?


 I like Email::Stuff


 I was very impressed with this. But it looks like it's got some XS
 dependencies (although checking the code Clone doesn't seem to actually be
 used, but Params::Util is an issue). I've emailed Adam incase there is a
 Pure Perl solution/work around to this.


 Stewart Heckenberg wrote:

 I like MIME::Lite -- has a very simple attachment interface :)


 Pure Perl and looks promising, thanks :)


 Lyle


 #  CGI::Application community mailing list  
 ####
 ##  To unsubscribe, or change your message delivery options,  ##
 ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
 ####
 ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
 ##  Wiki:  http://cgiapp.erlbaum.net/ ##
 ####
 



#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Michael Peters

Stewart Heckenberg wrote:

I like MIME::Lite -- has a very simple attachment interface :)


MIME::Lite is what I've used in the past, although the Perl Email folks don't recommend it. 
Apparently it's very crufty on the insides. I think they recommend Email::MIME instead.


--
Michael Peters
Plus Three, LP


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Octavian Rasnita

From: Michael Peters mpet...@plusthree.com

Stewart Heckenberg wrote:

I like MIME::Lite -- has a very simple attachment interface :)


MIME::Lite is what I've used in the past, although the Perl Email folks 
don't recommend it. Apparently it's very crufty on the insides. I think 
they recommend Email::MIME instead.


Email::MIME is in alpha version yet, although it could work fine. 
Email::Lite is too low level and it requires too much coding for a complex 
email message.


Mail::Builder::Simple is easier to use for sending complex email messages, 
with attachments, inline images, or create the message body or the 
attachments using Template-Toolkit or HTML::Template. It also automaticly 
encodes the message body and the headers to UTF-8 so they can contain 
non-english chars.
It uses Email::Send for sending email, so it doesn't have the bugs of some 
Mail::* modules.


Octavian


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Lyle


Lyle wrote:

Peter Karman wrote:
I like Email::Stuff   


I was very impressed with this. But it looks like it's got some XS 
dependencies (although checking the code Clone doesn't seem to 
actually be used, but Params::Util is an issue). I've emailed Adam 
incase there is a Pure Perl solution/work around to this.


Adam has got back to me already, Params::Util does have a Pure Perl 
option but it contained a bug. I was able to fix it a supply a patch, 
Adam took it further and wrote some tests to stop it from happening 
again. There is now a new version on it's way to CPAN :)



Hopefully an Email::Stuff update with Clone removed will follow suit and 
this module will be a viable option.



Lyle


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Lyle

Octavian Rasnita wrote:

From: Michael Peters mpet...@plusthree.com

Stewart Heckenberg wrote:

I like MIME::Lite -- has a very simple attachment interface :)


MIME::Lite is what I've used in the past, although the Perl Email 
folks don't recommend it. Apparently it's very crufty on the insides. 
I think they recommend Email::MIME instead.


Email::MIME is in alpha version yet, although it could work fine. 
Email::Lite is too low level and it requires too much coding for a 
complex email message.


Mail::Builder::Simple is easier to use for sending complex email 
messages, with attachments, inline images, or create the message body 
or the attachments using Template-Toolkit or HTML::Template. It also 
automaticly encodes the message body and the headers to UTF-8 so they 
can contain non-english chars.
It uses Email::Send for sending email, so it doesn't have the bugs of 
some Mail::* modules.


Octavian


This looks great, but it leans heavily on CPAN and there are several XS 
modules I don't think I could resolve :/



Lyle


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Octavian Rasnita

From: Lyle webmas...@cosmicperl.com
Mail::Builder::Simple is easier to use for sending complex email 
messages, with attachments, inline images, or create the message body or 
the attachments using Template-Toolkit or HTML::Template. It also 
automaticly encodes the message body and the headers to UTF-8 so they can 
contain non-english chars.
It uses Email::Send for sending email, so it doesn't have the bugs of 
some Mail::* modules.


Octavian


This looks great, but it leans heavily on CPAN and there are several XS 
modules I don't think I could resolve :/




Oh sorry, now I remember that the original question was about a module that 
doesn't use C code.


Octavian


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-30 Thread Lyle

Michael Peters wrote:

Stewart Heckenberg wrote:

I like MIME::Lite -- has a very simple attachment interface :)


MIME::Lite is what I've used in the past, although the Perl Email 
folks don't recommend it. Apparently it's very crufty on the insides. 
I think they recommend Email::MIME instead.


Email::MIME looks good, but Email::Stuff seems like an easier interface 
to it.


I notice that Email::Send now says to use Email::Sender instead. Anyone 
got any experience with this?



Lyle


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-29 Thread Peter Karman
Lyle wrote on 1/29/09 8:26 PM:
 Hi All,
  I wondering what peoples experiences are with email modules on CPAN.
 
 At the moment I've got a custom module that pipes to SendMail on Linux,
 and uses Net::SMTP on Windows. When it comes to adding features like
 attachments, etc, things are getting more complicated and I'm sure there
 are much better cross platform solutions already on CPAN.
 
 Any recommendations? Maybe a C::A::P wrapper around the best one(s)
 would be good?

I like Email::Stuff


-- 
Peter Karman  .  http://peknet.com/  .  pe...@peknet.com

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-29 Thread Stewart Heckenberg
I like MIME::Lite -- has a very simple attachment interface :)

2009/1/30 Peter Karman pe...@peknet.com:
 Lyle wrote on 1/29/09 8:26 PM:
 Hi All,
  I wondering what peoples experiences are with email modules on CPAN.

 At the moment I've got a custom module that pipes to SendMail on Linux,
 and uses Net::SMTP on Windows. When it comes to adding features like
 attachments, etc, things are getting more complicated and I'm sure there
 are much better cross platform solutions already on CPAN.

 Any recommendations? Maybe a C::A::P wrapper around the best one(s)
 would be good?

 I like Email::Stuff


 --
 Peter Karman  .  http://peknet.com/  .  pe...@peknet.com

 #  CGI::Application community mailing list  
 ####
 ##  To unsubscribe, or change your message delivery options,  ##
 ##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
 ####
 ##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
 ##  Wiki:  http://cgiapp.erlbaum.net/ ##
 ####
 



#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Best email module?

2009-01-29 Thread Lyle

Peter Karman wrote:

Lyle wrote on 1/29/09 8:26 PM:
  

Hi All,
 I wondering what peoples experiences are with email modules on CPAN.

...

Any recommendations? Maybe a C::A::P wrapper around the best one(s)
would be good?



I like Email::Stuff
  


I was very impressed with this. But it looks like it's got some XS 
dependencies (although checking the code Clone doesn't seem to actually 
be used, but Params::Util is an issue). I've emailed Adam incase there 
is a Pure Perl solution/work around to this.



Stewart Heckenberg wrote:

I like MIME::Lite -- has a very simple attachment interface :)
  


Pure Perl and looks promising, thanks :)


Lyle


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####