Mail::Lite not finding file??

P

p cooper

I can convert a pipe-delimited file to *.xls and can read it locally using
excel.

I then try to attach it to an email:
at the other end the email comes through with a 0K (empty) attachment with
the correct name.
Im using a defined variable for the path and filename in case it was typos.

In addition running the script from the command line generates no errors
and the message comes through the system.
Run from the browser I get

Can't call method "add_worksheet" on an undefined value
at /home/servers/ais/cgi-bin/excel.pl line 23.
(historical path...)
Not sure if they are related........

#!/usr/bin/perl -w
use CGI qw :)cgi-lib standard carpout); # Include CGI functions
use CGI::Carp qw(fatalsToBrowser); # Send error messages to browser
use Fcntl ':flock'; # import LOCK_* constants
use strict;
use Spreadsheet::WriteExcel;
use MIME::Lite;

my $path ="/home/paul/";
my $dbfile='db.xls';
my $pathdb=$path.$dbfile;
# Create a new Excel workbook
my $workbook = Spreadsheet::WriteExcel->new($pathdb);
# Add a worksheet
my $worksheet = $workbook->add_worksheet();
open(FH,"</tmp/results");
my @data=(<FH>);
close (FH);
my $n=1;
foreach my $i (@data)
{
chomp $i;
my @a = split(/\|/, $i);
$array_ref = \@a;
$worksheet->write($n, 0, $array_ref);
$n++;
}
my $message = MIME::Lite->new(
From => '(e-mail address removed)' ,
To => '(e-mail address removed)' ,
Cc =>'(e-mail address removed)',
Subject => "The database file as an Excel format",
Type => "text/plain",
Encoding => '7bit',
Data => "Database file"
);
my ($mime_type, $encoding) = ('application/vnd.ms-excel', 'base64');

$message->attach (
Type => $mime_type ,
Encoding => $encoding ,
Path => $pathdb ,
Filename => 'database.xls'
);
# ----- Tell MIME::Lite to use Net::SMTP instead of sendmail
MIME::Lite->send('smtp', 'smtp.isp.com', Timeout => 20);

$message->send;
 
P

p cooper

sorry -current version is this:


my $message = MIME::Lite->new(
From => '(e-mail address removed)' ,
To => '(e-mail address removed)' ,
Cc =>'(e-mail address removed)',
Subject => "The database file as an Excel format",
Type => 'multipart/mixed',
Encoding => '7bit',
# Data => "Database file"
);
my ($mime_type, $encoding) = ('application/vnd.ms-excel', 'base64');

$message->attach(Type => 'TEXT',
Data => 'I hope you can use this!');

$message->attach (
Type => $mime_type ,
# Encoding => $encoding ,
Path => $pathdb ,
Filename => 'database.xls'
);
# ----- Tell MIME::Lite to use Net::SMTP instead of sendmail

MIME::Lite->send('smtp', 'smtp.blueyonder.co.uk', Timeout => 20);

$message->send;
 
P

p cooper

but I still get this when calling it from a browser
Can't call method "add_worksheet" on an undefined value
at /home/servers/ais/cgi-bin/excel.pl line 23.
router paul # cat -n /home/servers/aninfosys/cgi-bin/excel.pl

17 my $path ="/home/paul/";
18 my $dbfile='db.xls';
19 my $pathdb=$path.$dbfile;
20 # Create a new Excel workbook
21 my $workbook = Spreadsheet::WriteExcel->new($pathdb);
22 # Add a worksheet
23 my $worksheet = $workbook->add_worksheet();
24 # Add and define a format
25 my $format = $workbook->add_format(); # Add a format
26 # $format->set_bold();
 
B

Ben Morrow

p cooper said:
but I still get this when calling it from a browser
Can't call method "add_worksheet" on an undefined value
at /home/servers/ais/cgi-bin/excel.pl line 23.
router paul # cat -n /home/servers/aninfosys/cgi-bin/excel.pl

17 my $path ="/home/paul/";
18 my $dbfile='db.xls';
19 my $pathdb=$path.$dbfile;
20 # Create a new Excel workbook
21 my $workbook = Spreadsheet::WriteExcel->new($pathdb);
22 # Add a worksheet
23 my $worksheet = $workbook->add_worksheet();

Chances are the permissions on /home/paul/db.xls are wrong. They
should be 0666; and if the file doesn't exist, you will need 777
permissions on the directory it's in as well. I'd suggest you create
the file in /tmp if all you are doing with it is mailing it somewhere.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top