Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Email Modules

by cjf (Parson)
on May 31, 2002 at 19:08 UTC ( [id://170808]=perlquestion: print w/replies, xml ) Need Help??

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

This almost seems like a Faq, but several super searches didn't turn up much, so here goes it...

I have somehow managed to avoid sending email through Perl scripts in most of my projects to date. In the few cases where I have sent mail, I've used Mail::Sendmail. This isn't because I've analyzed all the options and concluded that Mail::Sendmail is the best suited to my task, but because I knew how to use it, and it seemed to get the job done okay.

There are a several drawbacks to Mail::Sendmail such as reading the entire message into memory twice. I'd also like to see how the other modules compare to it, so I'm looking for different options.

A search through cpan turns up many relevant modules including ones I've heard recommended extensively such as:

My questions are, what module(s) do you use to send email and what do you view as their advantages? Further, is it best to combine 2 modules such as lhoward suggests doing with Mime::Lite and Net::SMTP in this node? Thanks for your replies.

Replies are listed 'Best First'.
Re: Email Modules
by Rich36 (Chaplain) on May 31, 2002 at 19:30 UTC
    I like Mail::Mailer - very easy to use and it seems pretty dependable. The drawback is that I don't believe that it's cross platform.
    use Mail::Mailer; my $mailer = Mail::Mailer->new("sendmail"); $mailer->open({From => "$from", To => "$to", Subject => "$subject", }) or die "Can't open: $!\n"; print $mailer $body; $mailer->close();

    Rich36
    There's more than one way to screw it up...

      Thanks for the suggestion, I hadn't heard much about Mail::Mailer before but it looks interesting. I especially like that it allows you to choose which program to send the mail. The 'test' feature described in the docs also looks useful.

      As for not being cross platform, it's passed tests on i386-linux, i686-linux, and sun4-solaris so that's not a problem for me. Thanks again :).

Re: Email Modules
by webfiend (Vicar) on May 31, 2002 at 19:22 UTC

    Let's see. I've used Mail::Sender and Mail::Sendmail, but not enough to say "one of these is better".

    Like you, I've mainly used Mail::Sendmail because of the fact that it's more familiar to me. It worked fine for me in a few mass-mailing tasks involving 3000-4000 emails at a shot... *shudder* the boss told me the list was subscription-only, but I still felt dirty sending out mass mailings...

    In other words, I can't tell you how good the alternatives are, but I can say that Mail::Sendmail put up with the most stressful tests I'm ever going to put it through.


    "All you need is ignorance and confidence; then success is sure."-- Mark Twain
Re: Email Modules
by oakbox (Chaplain) on May 31, 2002 at 21:22 UTC
    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 :)
      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

      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.

      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.
Re: Email Modules
by NaSe77 (Monk) on Jun 03, 2002 at 09:37 UTC
    i dont want to be kind of heretic but this question is kind of topic in the resent voting on <a href=">http://use.perl.org/pollBooth.pl?section=&qid=13&aid=-1"> use.perl.org ....
    there are some more or less usefull answers too

    ----
    NaSe
    :x

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2024-04-18 14:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found