mail attachments

Craig Freter freter at freter.com
Thu Nov 25 12:35:10 CST 1999


All,

I just wrote a test program to send multiple mail attachments.  I
thought perhaps the Baltimore PM list might find it interesting.

#!/usr/local/bin/perl -w

use strict;
use MIME::Base64;

# system programs
my $mail_prog = "/usr/lib/sendmail -t";

# create Base64 encoded message
my $message =
'This is a Base64
encoded message';
my $encoded = encode_base64($message);

# fork sendmail
open MAIL, "| $mail_prog" or die "can't fork $mail_prog";

print MAIL <<MESSAGE;
To: freter\@freter.com
Subject: Mail attachment
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=boundary-1

Message preamble.  Mime enabled readers should not
display this text.

--boundary-1
Content-Type: text/plain; charset=US_ASCII

Text Attachment number one.

--boundary-1
Content-Type: text/plain; charset=US_ASCII

Text Attachment number two.

--boundary-1
Content-Type: text/plain; charset=US_ASCII
Content-Transfer-Encoding: Base64

$encoded

--boundary-1--

MESSAGE

close MAIL;
die "$mail_prog failed: $?" if $?;


-- 
All that is complex is not useful,
and all that is useful is simple.
                       -- Mikhail Kalashnikov



More information about the Baltimore-pm mailing list