Ken Barker wrote:
> I am attempting to attach multiple spreadsheets to an e-mail. I can get it
> to work fine for a single attachment but do not understand what parameters I
> am missing to attach the subsequent files.
>
> Here is what works for a single:
Here is the same code sending two duplicate attachments (I changed
it from inline cause your mailer can only render gifs and jpegs etc.)
I normally would use MIME::Lite to do attachments.
use strict;
use warnings;
use Net::SMTP;
use MIME::Base64;
my $excel_file1 = 'yourexcelfile.xls';
my $file1 = $ARGV[0] || $excel_file1; # file to attach
my $ct = 'application/vnd.ms-excel'; # content type for attachment
my $smtphost = '255.255.255.255'; # SMTP mail host
my $from = '[EMAIL PROTECTED]';
my $recipient1 = '[EMAIL PROTECTED]';
my $to = $recipient1;
my $content;
{ local $/ = undef; # slurp file
open IN, $file1 or die "Error opening $file1: $!";
binmode IN; $content = <IN>; close IN;
}
# skip encode if using text
my $encode = encode_base64 ($content); # base 64 encode it
my $boundary = '<------------ FUBAR: ';
my @chrs = ('0' .. '9', 'A' .. 'Z', 'a' .. 'z');
foreach (0..16) { $boundary .= $chrs[rand (scalar @chrs)]; }
$boundary .= ' ------------>';
my $len = length $encode;
my $msg = <<EOD;
From: $from
To: $to
Reply-To: $from
Subject: Subject Title
MIME-Version: 1.0
X-Mailer: fubar.pl
Content-Type: multipart/mixed; boundary="$boundary"
This is a multipart MIME-coded message
--$boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message body.
--$boundary
Content-Type: $ct; name="$file1"
Content-Disposition: attachment; filename="$file1"
Content-Transfer-Encoding: base64
Content-Length: $len
$encode
--$boundary
Content-Type: $ct; name="$file1"
Content-Disposition: attachment; filename="$file1"
Content-Transfer-Encoding: base64
Content-Length: $len
$encode
--$boundary--
EOD
my $smtp = Net::SMTP->new($smtphost, Debug => 0) or
die "Net::SMTP::new: $!";
$smtp->mail($from);
$smtp->recipient($recipient1);
$smtp->data();
$smtp->datasend($msg);
$smtp->dataend();
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs