I am having an issue with attaching 2 attachments one xip and other excel file with email and sending using perl sendmail. I tried to look on various forums and everywhere i get advice using MIME :: Lite. Unfortunately i cannot use it . I have tried to write a program on my own to send 2 attachments and sending using perl sendmail but program is not working. It is reading only first file for attachment purposes and ignores second one.I would appreciate if anyone can pinpoint error with my program.
-
use strict;
-
use warnings;
-
use Mail::Sendmail;
-
use MIME::QuotedPrint;
-
use MIME::Base64;
-
-
my $file1 = 'c:\test1.xls';
-
my $file2 = 'c:\sample.zip';
-
-
-
my $file3 = $file2 || $file1; # file to attach
-
-
my %mail = ( To => "abc@yahoo.com",
-
From => "def@yahoo.com",
-
Cc => "hij@yahoo.com",
-
Subject => "Two Attachments",
-
smtp => 'mac.abc.com'
-
);
-
-
my $content;
-
{ local $/ = undef; # slurp file
-
open IN, $file3 or die "Error opening $file3: $!";
-
binmode IN; $content = <IN>;
-
$mail{body} += encode_base64(<IN>);
-
close IN;
-
}
-
-
-
my $boundary = "====" . time() . "====";
-
$mail{'content-type'} = "multipart/mixed; boundary=\"$boundary\"";
-
-
my $message = encode_qp( $email_body );
-
-
my $len = length $$mail{body};
-
$mail{body} = <<EOD;
-
-
-
$boundary
-
Content-Type: text/plain; charset="iso-8859-1"
-
Content-Transfer-Encoding: quoted-printable
-
-
$message
-
$boundary
-
-
Content-Type: application/octet-stream; name="$file3"
-
Content-Disposition: attachment; filename="$file3"
-
Content-Transfer-Encoding: base64
-
Content-Length: $len
-
-
$mail{body}
-
--$boundary
-
Content-Type: application/vnd.ms-excel; name="$file3"
-
Content-Disposition: attachment; filename="$file3"
-
Content-Transfer-Encoding: base64
-
Content-Length: $len
-
-
$mail{body}
-
$boundary--
-
END_OF_BODY
-
-
-
-
sendmail(%mail) or die $Mail::Sendmail::error;
-
-
open(OUT, ">>$sendmail_log") or die "Cannot open LOG file $file3: $!";
-
print OUT $Mail::Sendmail::log;
-
print OUT "\n==============================================================================\n";
-
close(OUT);
-