Experts,
I wrote a small testing code to send email with an attachment using MIME::Lite. I can receive the email with the attachment. However, the size of the attachment is always ZERO bytes.
The following is my code:
Thank you for your help!
I wrote a small testing code to send email with an attachment using MIME::Lite. I can receive the email with the attachment. However, the size of the attachment is always ZERO bytes.
The following is my code:
Code:
use strict;
use MIME::Lite;
my $srceDir = './';
my $filename = $ARGV[0];
my $file = $srceDir.$filename;
if(-e $file) {
print "File '$file' exists!!\n";
}
else {
print "File '$file' does NOT exist!!\n";
exit 1;
}
my $txt = "This is a test to send an email with an attachment '$file'.";
my $msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Subject =>'testing',
Type =>'multipart/mixed'
);
$msg->attach(
Type => 'TEXT',
Data => "$txt"
);
$msg->attach(
Type => 'application/pdf',
Path => "$srceDir",
Filename => "$filename",
Disposition => 'attachment'
);
$msg->send;
print "Exit ...\n";
exit 0;
Thank you for your help!