The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Mail::Mailer - Simple interface to electronic mailing mechanisms


    use Mail::Mailer;
    use Mail::Mailer qw(mail);    # specifies default mailer

    $mailer = new Mail::Mailer;

    $mailer = new Mail::Mailer $type, @args;


    print $mailer $body;



Sends mail using any of the built-in methods. As $type you can specify any of:

sendmail Use the sendmail program to deliver the mail.

Use the smtp protocol via Net::SMTP to deliver the mail. The server to use can be specified in @args with

    $mailer = new Mail::Mailer 'smtp', Server => $server;

The smtp mailer does not handle Cc and Bcc lines, neither their Resent-* fellows. The Debug options enables debugging output from Net::SMTP.

You may also use the Auth => [ $user, $password ] option for SASL authentication (requires Authen::SASL and MIME::Base64).


Use qmail's qmail-inject program to deliver the mail.


Used for debugging, this displays the data to the file named in $Mail::Mailer::testfile::config{outfile} which defaults to a file named mailer.testfile. No mail is ever sent.

Mail::Mailer will search for executables in the above order. The default mailer will be the first one found.


new can optionally be given a $type, which is one sendmail, mail, ... given above.

open is given a reference to a hash. The hash consists of key and value pairs, the key being the name of the header field (eg, To), and the value being the corresponding contents of the header field. The value can either be a scalar (eg, or a reference to an array of scalars (eg, ['', '']).


Assist formatting of fields in ...::rfc822:send_headers to ensure valid in the face of newlines and longlines etc.

Secure all forms of send_headers() against hacker attack and invalid contents. Especially "\n~..." in ...::mail::send_headers.



Augments/override the build in choice for binary used to send out our mail messages.



Example: assume you want you use private sendmail binary instead of mailx, one could set PERL_MAILERS to:


On systems which may include : in file names, use | as separator between type-groups.





Maintained by Mark Overmeer <>

Original code written by Tim Bunce <>, with a kick start from Graham Barr <>. With contributions by Gerard Hickey <> Small fix and documentation by Nathan Torkington <>.