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

I'm posting anonymously 'cause I'm actually a little embarrassed at how much trouble I'm having at finding a solution...

I need a module for sending email with the following characteristics:

I don't need attachments or anything fancy like that (though I wouldn't reject it!) just plain-text email. Here's an example of how simple I'm hoping for...
use Email::Foo; my $msg = Email::Foo->new(); $msg->smtp_server('smtp.mydomain.com'); $msg->set_from('me@mydomain.com'); $msg->add_recipient('joe@domain.com'); $msg->add_recipient('larry@otherdomain.com'); $msg->set_subject('Regarding your widget purchase'); $msg->set_body(<<'END_MSG'); Hello, Good Sir! Would you like a free cookie with your orange juice? My hovercraft is full of eels! Please remember to wear a sweater when crossing the street. Regards, Mortimer J. Paulinskil END_MSG $msg->send() or print $msg->error();

Replies are listed 'Best First'.
Re: Simplest module for sending email
by mr_mischief (Monsignor) on Oct 11, 2007 at 17:29 UTC
    Net::SMTP is nearly that simple, and it's a core module.
Re: Simplest module for sending email
by GrandFather (Saint) on Oct 11, 2007 at 17:51 UTC

    I don't know about its dependencies, but Mime::Lite otherwise fits the bill pretty well:

    use Mime::Lite; MIME::Lite->send ('smtp', 'smtp.mydomain.com'); my $msg = MIME::Lite->new ( From => 'me@mydomain.com', Subject => 'Regarding your widget purchase', ); $msg->add (To => 'joe@domain.com'); $msg->add (To => 'larry@otherdomain.com'); $msg->Add (Data => <<'END_MSG'); Hello, Good Sir! Would you like a free cookie with your orange juice? My hovercraft is full of eels! Please remember to wear a sweater when crossing the street. Regards, Mortimer J. Paulinskil END_MSG $msg->send ();

    Perl is environmentally friendly - it saves trees
Re: Simplest module for sending email
by hangon (Deacon) on Oct 11, 2007 at 19:12 UTC

    You might also want to look at Mail::Sender. Here's a simple way to use it for your example. Note that arguments are hashrefs. It can also do attachments and more complex stuff. Prerequisite is MIME::Base64.

    use Mail::Sender; my $msg = new Mail::Sender{smtp => 'smtp.mydomain.com'}; my %message = ( to => 'joe@domain.com, larry@otherdomain.com', from => 'me@mydomain.com', subject => 'Regarding your widget purchase', msg => <<'END_MSG' Hello, Good Sir! Would you like a free cookie with your orange juice? My hovercraft is full of eels! Please remember to wear a sweater when crossing the street. Regards, Mortimer J. Paulinskil END_MSG ); # sends message, errors are returned in $status my $status = $msg->MailMsg(\%message);
Re: Simplest module for sending email
by sago (Scribe) on Oct 12, 2007 at 06:15 UTC

    use Net::SMTP;

    my $smtp = Net::SMTP->new('mailhub.yahoo.com');
    my $MailFrom = "test_test\@yahoo.com";
    $smtp->mail( $MailFrom );
    $smtp->recipient("san.gov\@yahoo.com", { SkipBad => 1 });
    $smtp->data();
    $smtp->datasend("Subject: Test mail");
    $smtp->datasend("\n");
    $smtp->datasend("\n");
    $smtp->dataend();
    $smtp->quit;
Re: Simplest module for sending email
by Hercynium (Hermit) on Oct 11, 2007 at 19:34 UTC
    Thanks! I think I've been suffering from CPAN-vertigo. So many modules for email makes this monkey dizzy sometimes.

    For the curious, here's what I ended up with:
Re: Simplest module for sending email
by dwm042 (Priest) on Oct 11, 2007 at 23:53 UTC
    I'm quite fond of Mail::Sendmail when I want to send email to servers other than localhost.

    David.
Re: Simplest module for sending email
by leocharre (Priest) on Oct 11, 2007 at 19:32 UTC
    It depends what your host is supposed to be doing. Is this for a cgi? then.. maybe an interface to sendmail would be good.

    You can always do the stupid and dangerous .. open a pipe to the sendmail bin path and ..

    # UNTESTED my $sendmail_bin = '/bin/sendmail'; # maybe use File::Which::which(), +might not work on a cgi for example open(OUT, "|$sendmail_bin -t") or die("cant open pipe to sendmail [$se +ndmail_bin]"); my ($from, $recipient, $subject, $reply)= qw(me@this.net user@destination.ext bogus no@reply.net); # print header and content print OUT <<EOM From : $from To: $recipient Subject: $subject Reply-To: $reply [This message is junk.] Hi hi.. whatzzzzzuuuupppp... EOM ; close(OUT);
Re: Simplest module for sending email
by chrism01 (Friar) on Oct 12, 2007 at 00:56 UTC
    My option:

    use Mail::Mailer; # Access sendmail/whatever sub send_email { my ( $error_msg, # input error msg $hostname, # name of this box for sending $prog_full_name, # prog path + name $contact_email, # contact email address $mailer, # mailer object $sender, # sender of email as specified in cfg file $subject, # subject line in email $body_text # actual email msg text ); # Assign input params $error_msg = $_[0]; # Get hostname anyway we can using Sys::Hostname; # tries syscall(SYS_gethostname), `hostname`, `uname -n` $hostname = Sys::Hostname::hostname(); # Get program full path name $prog_full_name = cwd()."/${0}"; # Set the fields required by Mailer... $contact_email = $cfg::params{'ADMIN_EMAIL'}; $sender = "$prog_full_name"; $subject = "$prog_full_name: Error trapped"; $body_text = "This is an automated message:\n\n". "$error_msg\n\n". "Regards,\n$prog_full_name at $hostname\n\n"; # ... and send it $mailer = Mail::Mailer->new(); $mailer->open({ From => $sender, To => $contact_email, Subject => $subject, }) or print "Can't open Mailer for send: $!\n"; print $mailer $body_text; close($mailer) or print "Can't close Mailer: $!\n"; } called as send_email("<your msg here>"); You can optionally specify the mail prog to be used (see the CPAN page +), or let it find one.
    Cheers
    Chris
Re: Simplest module for sending email
by DrHyde (Prior) on Oct 12, 2007 at 10:54 UTC
    I use MIME::Lite for sending mail, even though I generally just send plain text with no need for fancy encoding or attachments. It's dead simple and can be configured to work how you want. It does, howver, have quite a lot of dependencies. But unlike lots of other modules with that sort of number of deps, nigh-on all of them Just Work.