PDA

View Full Version : Mail::Sender attach file problem?


johny
09-15-2003, 12:25 PM
Hi, all:

I can use Mail::Sender to send mails. But when I add attachments, problems come. I don't know why it always
complains that the file can't be found. My script is:

-------------------------------------------
use strict;
use Mail::Sender;
use CGI qw(:standard);

my $sender = new Mail::Sender {
smtp => 'my.smtp.server',
from => 'my@comp.com',
on_errors => undef
} or die "Can't create the Mail::Sender object:
$Mail::Sender::Error\n";
$sender->OpenMultipart({
to => 'someone@outthere.com',
subject => 'Hello, I\'ll come.'
}) or die "Can't open the message: $sender->{'error_msg'}\n";
$sender->Body;
$sender->SendEnc(<<'*ABC*');
Here is a new module Mail::Sender.
It provides an object based interface to sending SMTP mails.
It uses a direct socket connection, so it doesn't need any additional
program.

Enjoy, Jedi
*ABC*
$sender->Attach({
description => 'Perl module Mail::Sender.pm',
ctype => 'application/x-zip-encoded',
encoding => 'Base64',
disposition => 'attachment; filename="Mail-Sender.zip"; type="ZIP
archive"',
file => "./Mail-Sender.zip"
});
$sender->Close or die "Failed to send the message:
$sender->{'error_msg'}\n";

print header(), start_html("Sendmail");
print p("Mail sent successfully!\n");
print end_html();

exit (0);
-------------------------------------------

I have an Apache web server, and put this perl script into /cgi-bin/ to let it run by mod_perl modle.

I put the file Mail-Sender.zip in the same folder as this script.
Then I run it from the browser as:

http://12.345.67.89/cgi-perl/mail/testmail.pl

The error is:

[Mon Sep 15 16:15:52 2003] [error] Failed to send the message: File
"./Mail-Sender.zip" not found

The error persists even as I write:

file => "http://$ENV{'HTTP_HOST'}/Mail-Sender.zip"

But when I write the following:

file => "d:/apache group/apache/htdocs/cgi-perl/mail/Mail-Sender.zip"

The script runs well, and the mail can be sent out.

Any idea on this issue?

thanks,