in reply to Email Modules

I can recommend MIME::Lite if you are going to be sending out multipart messages. It's basic as hell to set up and use in a script. Anytime I need a quick and dirty HTML mailer from within a customer's script, this is what I use.

For more robust applications sending out MIME (a web mailer, for example) I use the MIME::Tools library and build it myself. This is a little more work, but I like the level of control it gives me in constructing the headers and message.

Having said all that, if you are just sending plain text messages, why not just:

open (MAIL,"| /usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $fromaddr\n"; print MAIL "Subject: $subject\n\n"; print MAIL "$message"; print MAIL "\n.\n"; close(MAIL);
It's basic, it's fast, it's portable, and you don't have to worry about installing a whole module to send a message.
-oakbox
Update : My pipe was broken :)

Replies are listed 'Best First'.
Re: Re: Email Modules
by rob_au (Abbot) on Jun 01, 2002 at 08:32 UTC
    It's basic, it's fast, it's portable, and you don't have to worry about installing a whole module to send a message.
     

    I strongly disagree with this - This approach is by far not portable as it depends on a number of factors:

    • the installation of sendmail on the local machine; this is most certainly not a given, particularly when the script may be run in a Windows environment,
    • the installation of the sendmail binary in the /usr/sbin directory; other common locations for this binary include /usr/lib and /opt/bin, and,
    • the correct configuration of sendmail for mail delivery in the manner required.

    Furthermore, as for the ease of using this approach without installing modules, the Net::SMTP module is included as part of the core Perl installation and as such should be available on all installations. Additionally the use of this module is very straight-forward, for example,

    my $smtp = Net::SMTP->new('mail.mydomain.com'); $smtp->mail($fromaddr); $smtp->to($to); $smtp->data(); $smtp->data("Subject: $subject\n\n"); $smtp->data($message); $smtp->dataend(); $smtp->quit;

    Furthermore, the use of the local network SMTP server will make your network administrator happier as it is at this point that network mail policies and statistics reporting is often based.

     

      Using Net::SMTP is a little more portable than piping to /usr/sbin/sendmail but not half as portable as using a general mail sending module such as Mail::Sendmail or MIME::Lite (all of them have an ability to send mail via SMTP).

      Besides, I cannot find Net::SMTP among perl core modules neither in 5.6.1 not earlier versions. There's a recent node on the topic.

      This approach is by far not portable as it depends on a number of factors:

      Pipe to sendmail IF: You are on a *nix variant and know where the sendmail binary is. But I should mention that most distributions recognize sendmail as the defacto email server. Even Qmail recommends symlinking to the /usr/sbin/sendmail location.


      -oakbox

Re: Re: Email Modules
by Marza (Vicar) on May 31, 2002 at 23:17 UTC

    I would second that. I had to build a report mail as the user did not want a report file.

    Mime made it really easy. If you need to do html mail stuff, you might look at the HTML::FromText as well. It helped on a couple issues.

Re: Re: Email Modules
by kappa (Chaplain) on Jun 02, 2002 at 13:08 UTC
    I'd like to add, that with MIME::Lite you get several important features in one module: extremely easy mail construction, full MIME support and the ability to send the mail right away using your favourite way of sending mails.