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;

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:

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.

If you have a question, put $5 at patreon and message me.


  1. Perl Overview
  2. Version String
  3. Help System


  1. Quoting String
  2. Format String
  3. String Operations
  4. True, False
  5. if then else
  6. Loop
  7. List / Array
  8. Loop Thru List
  9. Map f to List
  10. List Comprehension
  11. Hash Table
  12. Function Optional Param
  13. regex

Text Processing

  1. Unicode 🐪
  2. Convert File Encoding
  3. Read Write File
  4. Traverse Dir
  5. Find Replace
  6. Validate Local Links
  7. Split Line by Regex


  1. Sort List, Matrix, Object
  2. Sort Matrix
  3. Sort Unstable
  4. Sort Misc
  5. List Modules, Search Paths
  6. Write a Module
  7. Complex Numbers
  8. System Call
  9. gzip
  10. Get Env Var
  11. GET Web Content
  12. Email