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

Wise monks, I need to send out mails using Perl. I am a little wary about using third party software like sendmail. So does anyone have any experience of using some module? What works best and why?

Replies are listed 'Best First'.
Re: Sending mail using perl
by Tanktalus (Canon) on Mar 02, 2005 at 04:59 UTC
Re: Sending mail using perl
by gube (Parson) on Mar 02, 2005 at 06:11 UTC
Re: Sending mail using perl
by InfiniteLoop (Hermit) on Mar 02, 2005 at 05:14 UTC
Re: Sending mail using perl
by inman (Curate) on Mar 02, 2005 at 08:52 UTC
    I cut this example out of an existing App. There may be bits miissing.
    #! /usr/bin/perl -w use strict; use warnings; use Mail::Sender; my $debug = 1; my $sender = 'me@mydomain.com'; my $smtp = 'smtp.mydomain.com'; my @mailtoList = qw (bob@mydomain.com betty@mydomain.com ruphal@otherd +omain.com); sendMail ('subject', 'message'); sub sendMail { my $subject = shift; my $tolist = join ', ', @mailtoList; my $mailer = new Mail::Sender { smtp => $smtp, from => $sender , to => $tolist }; # Add timestamp unshift @_, scalar localtime, ""; if ($mailer->Open({subject => $subject})) { foreach (@_) { $mailer->SendLineEnc($_); print "$_\n" if $debug; } $mailer->Close; } }
Re: Sending mail using perl
by bradcathey (Prior) on Mar 02, 2005 at 12:55 UTC

    Someone here at the Monastery got me onto Mime::Lite which I like over Mail::Sendmail which I was using. Mime::Lite makes adding attachments so much easier.

    use MIME::Lite; for (@email_recipients) { #-- create the multipart container my $msg = MIME::Lite->new ( From => $query->param('fromwho'), To => $_, Subject => $query->param('subject'), Type =>'multipart/mixed' ) or die "Error creating multipart container: $!\n"; #-- add the text message part $msg->attach ( Type => 'TEXT', Data => $query->param('message'), ) or die "Error adding the text message part: $!\n"; #-- add the ZIP file $msg->attach ( Type => 'AUTO', Path => "../".$file, Filename => $file, Disposition => 'attachment' ) or die "Error adding $file: $!\n"; $msg->send; sleep(1); }

    Note the use of the delay at the end of the loop. This avoids the batch e-mail appearance to some spam filters. However, it may be moot because many ISPs limit the number of emails you can send at once or in an hour.


    —Brad
    "The important work of moving the world forward does not wait to be done by perfect men." George Eliot
Re: Sending mail using perl
by pearlie (Sexton) on Mar 02, 2005 at 09:20 UTC
    Mail::Mailer is another module that can be used.
Re: Sending mail using perl
by tirwhan (Abbot) on Mar 02, 2005 at 11:18 UTC
    These days I use Email::Send and it works rather well for me. This module is part of the of the Perl Email Project which aims to replace the more traditional Mail::* modules.
Re: Sending mail using perl
by Anonymous Monk on Mar 02, 2005 at 17:46 UTC
    Be easy!

    use Mail::SendEasy ; Mail::SendEasy::send( from => 'sender@foo.com' , to => 'recp@domain.foo' , subject => "MAIL Test" , msg => "The Plain Msg..." , ) ;