Every program expands until it can send mail.

Mail::Sendmail tries to make this task easier by providing an interface to any SMTP server you specify. In hindsight, the name should rather have been Mail::Simple, but it's too late for that. An alternative to Mail::Sendmail is Net::SMTP, which has about the same feature set except MIME, but I have not (yet) looked closely enough to make a qualified comparision.

Why use Mail::Sendmail ?

You need to send mail and you're not sure that there will be a local mailer installed. Mail::Sendmail works under Windows and Unix (most likely, Mac too) and it's a pure Perl solution. Installation is easy even if you don't have a make utility installed, as it consists of only one file to copy. If you install MIME::QuotedPrint, you'll also be able to easily send attachments and HTML encoded Email. It only makes one connection to the SMTP server for all recipients of the email.

Why not use Mail::Sendmail ?

Mail::Sendmail needs an existing network connection to the internet, or at least an existing network connection to the SMTP server you want it to use. It does not support local queuing or anything fancy. It modifies the headers of your email to have Content-Type and Content-transfer-encoding headers, and it will automagically try to do the right thing and quote high-ASCII characters. If you have warnings on, it will warn quite a bit about stuff. Mail::Sendmail only exports one function, &sendmail(). If you need finer grained feedback, like progress, etc. or if you don't have enough memory to keep your email twice! in it, Mail::Sendmail is not for you.

Caveats

Mail::Sendmail tries to do the right thing. This might bring surprising results if you use high-ASCII stuff. Mail::Sendmail tries to parse the email adresses given, but it isn't completely RFC compliant. This might bite if you have really fancy email addresses.

Example

The Mail::Sendmail documentation already has an exhaustive example, but I'm reposting my test script which I used to check whether Mail::Sendmail works under Win32 :

#!/usr/bin/perl -w # Simple test script to test Mail::Sendmail under Win32 use strict; use Mail::Sendmail; # Set up some default configuration unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'smtprelay.t-online.de'; $Mail::Sendmail::mailcfg{'from'} = "Corion (script) <corion\@sends.no. +spam>"; my %mail = ( Bcc => 'corion@wants.no.spam', Subject => "Test 1", 'X-Mailer' => "Mail::Sendmail test script v0.01/$Mail::Sendmail::VER +SION", Message => "Test number 1", ); sendmail( %mail ) or die "Error: $Mail::Sendmail::error\n";

In reply to Mail::Sendmail by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.