Perl: Send Email

By Xah Lee. Date: .

There are several Perl packages for sending email. Here's a example of sending email using the package “Mail::Mailer”. This example is from perlfaq9.

# perl
use Mail::Mailer;

$mailer = Mail::Mailer->new();
$mailer->open({ From    => $from_address,
                To      => $to_address,
                Subject => $subject,
              })
  or die "Can't open: $!\n";
print $mailer $body;
$mailer->close();

perldoc perlfaq9

In Perl, there are several packages that do send mail, each with slight problems. Here's how the situation are back in 2001.

For Perl libraries that deals with RFC 821:

Mail::Mailer
Mentioned in most Perl books. Written or maintained by Graham Barr.
Mail::Send
Maintained by Graham Barr, originally written by Tim Bunce.
Mail::Sendmail
By Milivoj Ivkovic.

The first two has bugs. I forgot what they are exactly. I think Mail::Mailer has a bug on the from field. i.e. it ignores what you gave. I'm currently using Mail::Sendmail, and according to a ex-colleague, it has problems with some DNS mail exchange entries.

For some discussion of Perl mail modules and their shortcomings, see “Two modules and a few links related to Perl and Internet mail” (1999) by Milivoj Ivkovic. http://alma.ch/perl/mail.htm