I'm having this weird problem with the mail::sender module. I kind of
hacked(wrote) a script that uploads and emails a file. The script
uploads the file
fine, it uses cgi-lib and mail::sender. The probelm I have is that
somehow it doesn't e-mail all the times, althought it uploads the file
each time. At first I
thought it was the perl version I was running on which was 5.005, the
reason I thought that was because I installed the script on
another server which had the same O/S (Linux) but with perl 5.6 and
the script worked each time. So I upgraded perl to 5.6 and I still had
the same probelm, whenever the script feels like sending an e-mail it
does. I have no clue!!!! The one other difference between the server
that the script is working on and the one that's not is that they have
different smtp servers, the one that works on I think uses a microsoft
exchange server and the one that sometimes works uses EXIM ???? I read
in the mail::sender documentation that mail::sender doesn't work with
qmail. Is exim and qmail the same ??? I really don't know if they are
or not and have no idea on how to debug this problem.
Any help is much apreciated!!!!
Thanks
Here's the script
#!/usr/bin/perl -Tw
#require 5.001;
use strict;
require "./cgi-lib.pl";
use Mail::Sender;
MAIN:
{
my (%cgi_data, %cgi_cfn, %cgi_ct, %cgi_sfn, $ret, $buf );
# When writing files, several options can be set..
$cgi_lib::writefiles = "/tmp";
# Limit upload size to avoid using too much memory
$cgi_lib::maxdata = 500000;
$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);
if (!defined $ret)
{
&CgiDie("Error in reading and parsing of CGI input"
}
elsif (!$ret)
{
&CgiDie("Missing parameters\n",
"Please complete the form ",
"<a href=' "upload.html</a>\n"
}
elsif (!defined $cgi_data{'upfile'} )
{
&CgiDie("Data missing\n", "Please specify a file\n"
}
rename "$cgi_data{'upfile'}","$cgi_lib::writefiles/$cgi_cfn{'upfile'}";
my $newPerm = '0777';
my $mode = oct($newPerm);
my $uploadFile = "/tmp/$cgi_cfn{'upfile'}";
chmod $mode, $uploadFile;
my $sender;
my $compName = " Company Name: $cgi_data{'compname'}";
my $contact = " Contact Name: $cgi_data{'contactname'}";
my $phone = " Phone Num: $cgi_data{'phonenum'}";
my $fax = " Fax Num: $cgi_data{'fax'}";
my $emailAddr = "Email Address: $cgi_data{'retemail'}";
my $instrCom = "Instruction-Commentse: $cgi_data{'instruct'}";
ref ( $sender = new Mail::Sender { from => 'script@testing.com',
smtp => 'mail.testing.com',
boundary => 'This-is-a-mail-boundary-435427'})
or die "Error($sender) : $Mail::Sender::Error\n";
$sender->OpenMultipart({to => 'testing@testing.com',
subject => 'File Uploaded'});
$sender->Body;
$sender->SendLine($compName);
$sender->SendLine($contact);
$sender->SendLine($phone);
$sender->SendLine($fax);
$sender->SendLine($emailAddr);
$sender->SendLine;
$sender->SendLine($instrCom);
$sender->SendFile({description => 'Uploaded file',
ctype => $cgi_ct{'upfile'},
encoding => 'Base64',
disposition => 'attachment; filename="Uploaded
File"; type="gif"', file => $uploadFile });
$sender ->Close;
unlink ($uploadFile) or
&CgiError("Error: Unable to delete file",
"Error: Unable to delete file $uploadFile: $!\n"
$cgi_lib::writefiles = $cgi_lib::writefiles;
$cgi_lib::maxdata = $cgi_lib::maxdata;
}
hacked(wrote) a script that uploads and emails a file. The script
uploads the file
fine, it uses cgi-lib and mail::sender. The probelm I have is that
somehow it doesn't e-mail all the times, althought it uploads the file
each time. At first I
thought it was the perl version I was running on which was 5.005, the
reason I thought that was because I installed the script on
another server which had the same O/S (Linux) but with perl 5.6 and
the script worked each time. So I upgraded perl to 5.6 and I still had
the same probelm, whenever the script feels like sending an e-mail it
does. I have no clue!!!! The one other difference between the server
that the script is working on and the one that's not is that they have
different smtp servers, the one that works on I think uses a microsoft
exchange server and the one that sometimes works uses EXIM ???? I read
in the mail::sender documentation that mail::sender doesn't work with
qmail. Is exim and qmail the same ??? I really don't know if they are
or not and have no idea on how to debug this problem.
Any help is much apreciated!!!!
Thanks
Here's the script
#!/usr/bin/perl -Tw
#require 5.001;
use strict;
require "./cgi-lib.pl";
use Mail::Sender;
MAIN:
{
my (%cgi_data, %cgi_cfn, %cgi_ct, %cgi_sfn, $ret, $buf );
# When writing files, several options can be set..
$cgi_lib::writefiles = "/tmp";
# Limit upload size to avoid using too much memory
$cgi_lib::maxdata = 500000;
$ret = &ReadParse(\%cgi_data,\%cgi_cfn,\%cgi_ct,\%cgi_sfn);
if (!defined $ret)
{
&CgiDie("Error in reading and parsing of CGI input"
}
elsif (!$ret)
{
&CgiDie("Missing parameters\n",
"Please complete the form ",
"<a href=' "upload.html</a>\n"
}
elsif (!defined $cgi_data{'upfile'} )
{
&CgiDie("Data missing\n", "Please specify a file\n"
}
rename "$cgi_data{'upfile'}","$cgi_lib::writefiles/$cgi_cfn{'upfile'}";
my $newPerm = '0777';
my $mode = oct($newPerm);
my $uploadFile = "/tmp/$cgi_cfn{'upfile'}";
chmod $mode, $uploadFile;
my $sender;
my $compName = " Company Name: $cgi_data{'compname'}";
my $contact = " Contact Name: $cgi_data{'contactname'}";
my $phone = " Phone Num: $cgi_data{'phonenum'}";
my $fax = " Fax Num: $cgi_data{'fax'}";
my $emailAddr = "Email Address: $cgi_data{'retemail'}";
my $instrCom = "Instruction-Commentse: $cgi_data{'instruct'}";
ref ( $sender = new Mail::Sender { from => 'script@testing.com',
smtp => 'mail.testing.com',
boundary => 'This-is-a-mail-boundary-435427'})
or die "Error($sender) : $Mail::Sender::Error\n";
$sender->OpenMultipart({to => 'testing@testing.com',
subject => 'File Uploaded'});
$sender->Body;
$sender->SendLine($compName);
$sender->SendLine($contact);
$sender->SendLine($phone);
$sender->SendLine($fax);
$sender->SendLine($emailAddr);
$sender->SendLine;
$sender->SendLine($instrCom);
$sender->SendFile({description => 'Uploaded file',
ctype => $cgi_ct{'upfile'},
encoding => 'Base64',
disposition => 'attachment; filename="Uploaded
File"; type="gif"', file => $uploadFile });
$sender ->Close;
unlink ($uploadFile) or
&CgiError("Error: Unable to delete file",
"Error: Unable to delete file $uploadFile: $!\n"
$cgi_lib::writefiles = $cgi_lib::writefiles;
$cgi_lib::maxdata = $cgi_lib::maxdata;
}