I find Mail::Sendmail to be easy, reliable and cross-platform.

However, also note that sending mail with attachments is really easy with MIME::Lite (although you need to install Net::SMTP to use this, as other folks have noted). MIME::Lite is available through Activestate's PPM, which makes life easier.

Check out this simple cross-platform (tested on Linux and NT). NT gives an annoying: "The system cannot find the path specified" error, but still works.

There are, of course, lots of ways to improve it (use a 'magic' file to discern the MIME type, use Getopt::Long for a more coherent command line, allow the user to set more parameters, etc.)

#!/usr/bin/perl use strict; use MIME::Lite; my $DEBUG = 0; my %TYPES = ( csv => [ 'text/csv', '8bit' ], gif => [ 'image/gif', 'base64' ], tiff => [ 'image/tiff', 'base64' ], tif => [ 'image/tiff', 'base64' ], jpeg => [ 'image/jpeg', 'base64' ], jpg => [ 'image/jpeg', 'base64' ], zip => [ 'application/zip', 'base64' ], gz => [ 'application/gzip', 'base64' ], html => [ 'text/html', '8bit' ], htm => [ 'text/html', '8bit' ], pdf => [ 'application/pdf', 'base64' ], ); { my $subject = shift; my $filetype = shift; my $filename = shift; my $email = shift; die "Usage: $0 subject file-type filename email\n" unless ( $email ) +; my %mail = ( subject => $subject, to => $email, from => 'webmaster@in +tes.net' ); my $msg = new MIME::Lite( From => $mail{from}, To => $mail{to}, Subject => $mail{subject}, Data => 'Emailing file; should be attached' +, Type => 'text/plain' ); my $type = $TYPES{ lc $filetype } || [ 'text/plain', '8bit' ]; $msg->attach( Type => $type->[0], Encoding => $type->[1], Path => $filename ); MIME::Lite->send( 'smtp', 'localhost', Timeout => 20 ); $msg->send || die "Cannot send message: $!"; }

In reply to RE: sending email by lachoy
in thread sending email by Anonymous Monk

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.