Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Recommendation for email sending modules please

by palkia (Monk)
on Sep 10, 2011 at 01:59 UTC ( [id://925180]=perlquestion: print w/replies, xml ) Need Help??

palkia has asked for the wisdom of the Perl Monks concerning the following question:

Hi
I found several of these actually but I always prefer to get some recommendation,
from people who actually used them before (especially on a regular basis).
So, what's your preferred (simple) mail sending module (from experience) ?

Thx
  • Comment on Recommendation for email sending modules please

Replies are listed 'Best First'.
Re: Recommendation for email sending modules please
by jettero (Monsignor) on Sep 10, 2011 at 02:46 UTC
    I'm most fond of Net::SMTP::OneLiner, of course I wrote that like 12 years ago. The more modern choice is MIME::Lite, a much better choice (generally speaking), particularly if you want to do attachments and things.
    Re: Recommendation for email sending modules please
    by zentara (Archbishop) on Sep 10, 2011 at 12:50 UTC
      Many use Net::SMTP_auth if authentication is needed , and MIME::Lite is very good for attachments of all sorts. The 2 modules are often used in combination like this ( no auth shown here, but google for other code examples):
      #!/usr/bin/perl use warnings; use strict; use MIME::Lite; use Net::SMTP; my $smtp = Net::SMTP ->new('yourmail.server'); #identify yourself to the server $smtp->mail('you@yourdomain'); $smtp->to('zentara@foobar.org'); $smtp->data( ); my $msg = MIME::Lite->new( From =>'Joe', To =>'Shmoe', Subject =>'HTML Test', Type =>'multipart/related', ); $msg->attach( Type => 'text/plain', Data => 'HERE IS YOUR HTML PAGE', ); $msg->attach( Type => 'text/html', Path =>'path_to_full_file_name', Disposition => 'attachment', ); # send the message over $smtp->datasend( $msg->as_string() ); # close smtp connection $smtp->dataend(); $smtp->quit;

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh
    Re: Recommendation for email sending modules please
    by duelafn (Parson) on Sep 10, 2011 at 19:33 UTC

      Plain Text Emails:

      use Email::Simple; use Email::Sender::Simple qw(sendmail); my $email = Email::Simple->create( header => [ From => "", To => "", Subject => "" ], body => $message, ); sendmail($email);

      HTML Emails (MIME::Lite::HTML will handle attaching images, css, ...):

      use MIME::Lite; use MIME::Lite::HTML; use HTML::FormatText::WithLinks; Send( { From => "", To => "", Subject => "" }, $html_message ); sub Send { state $mk_text = HTML::FormatText::WithLinks->new(); my ($opt, $html, $text) = @_; $text ||= $mk_text->parse($html); my $ml = MIME::Lite::HTML->new( TextCharset => 'UTF-8', TextEncoding => 'base64', HTMLCharset => 'UTF-8', %$opt, ); my $m = $ml->parse($html,$text); my @errors; die "@errors" if @errors = $ml->errstr; $m->send; }

      Good Day,
          Dean

        Thx
        I tried the 1st example but it didn't work from some reason.
        Please tell me what I'm doing wrong.
        use Email::Simple; use Email::Sender::Simple qw(sendmail); my $email = Email::Simple->create( header => [ From => 'a real email', To => 'my real email', Subject = +> "zzz" ], body => 'it work !', #no it's not ); sendmail($email);
        But it died saying
        unable to establish SMTP connection Trace begun at C:\strawberry\perl\site\lib\Email\Sender\Transport\SMTP +.pm line 9 5 Email::Sender::Transport::SMTP::_throw('Email::Sender::Transport::SMTP +=HASH(0x14 c7b04)', 'unable to establish SMTP connection') called at C:\strawberr +y\perl\sit e\lib\Email\Sender\Transport\SMTP.pm line 62 Email::Sender::Transport::SMTP::_smtp_client('Email::Sender::Transport +::SMTP=HAS H(0x14c7b04)') called at C:\strawberry\perl\site\lib\Email\Sender\Tran +sport\SMTP .pm line 104 Email::Sender::Transport::SMTP::send_email('Email::Sender::Transport:: +SMTP=HASH( 0x14c7b04)', 'Email::Abstract=ARRAY(0x38b1c)', 'HASH(0x12012a4)') call +ed at C:\s trawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 27 Email::Sender::Role::CommonSending::__ANON__ at C:\strawberry\perl\sit +e\lib\Try\ Tiny.pm line 76 eval {...} at C:\strawberry\perl\site\lib\Try\Tiny.pm line 67 Try::Tiny::try('CODE(0x1545c44)', 'Try::Tiny::Catch=REF(0x1541a64)') c +alled at C :\strawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 37 Email::Sender::Role::CommonSending::send('Email::Sender::Transport::SM +TP=HASH(0x 14c7b04)', 'Email::Abstract=ARRAY(0x38b1c)', 'HASH(0x14c8414)') called + at C:\str awberry\perl\site\lib\Email\Sender\Simple.pm line 110 Email::Sender::Simple::send_email('Email::Sender::Simple', 'Email::Abs +tract=ARRA Y(0x38b1c)', 'HASH(0x1201334)') called at C:\strawberry\perl\site\lib\ +Email\Send er\Role\CommonSending.pm line 27 Email::Sender::Role::CommonSending::__ANON__ at C:\strawberry\perl\sit +e\lib\Try\ Tiny.pm line 76 eval {...} at C:\strawberry\perl\site\lib\Try\Tiny.pm line 67 Try::Tiny::try('CODE(0xd0a83c)', 'Try::Tiny::Catch=REF(0x1283bdc)') ca +lled at C: \strawberry\perl\site\lib\Email\Sender\Role\CommonSending.pm line 37 Email::Sender::Role::CommonSending::send('Email::Sender::Simple', 'Ema +il::Simple =HASH(0x99659c)') called at C:\strawberry\perl\site\lib\Sub\Exporter\U +til.pm lin e 69 Sub::Exporter::Util::__ANON__('Email::Simple=HASH(0x99659c)') called a +t C:\Docum ents and Settings\Administrator\Desktop\perl experiments\mail sender.p +l line 9
        So I tried to add a use Email::Simple::Creator; line
        but nothing changed.

        help :-(

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlquestion [id://925180]
    Approved by ww
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others romping around the Monastery: (4)
    As of 2024-04-25 23:26 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found