Mail::Lite not finding file??

Discussion in 'Perl Misc' started by p cooper, Feb 1, 2004.

  1. p cooper

    p cooper Guest

    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 => '' ,
    To => '' ,
    Cc =>'',
    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 cooper, Feb 1, 2004
    #1
    1. Advertising

  2. p cooper

    p cooper Guest

    sorry -current version is this:


    my $message = MIME::Lite->new(
    From => '' ,
    To => '' ,
    Cc =>'',
    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 cooper, Feb 1, 2004
    #2
    1. Advertising

  3. p cooper

    p cooper Guest

    fixed - I need a $workbook-> close before doing anything with it
    p cooper, Feb 1, 2004
    #3
  4. p cooper

    p cooper Guest

    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();
    p cooper, Feb 1, 2004
    #4
  5. p cooper

    Ben Morrow Guest

    p cooper <> wrote:
    > 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

    --
    "If a book is worth reading when you are six, *
    it is worth reading when you are sixty." - C.S.Lewis
    Ben Morrow, Feb 1, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Elhanan Maayan
    Replies:
    0
    Views:
    833
    Elhanan Maayan
    May 3, 2004
  2. Aaron Brady

    SQL, lite lite lite

    Aaron Brady, Dec 29, 2008, in forum: Python
    Replies:
    15
    Views:
    734
    Aaron Brady
    Jan 1, 2009
  3. Jane Humbrey
    Replies:
    5
    Views:
    263
    Jane Humbrey
    Sep 1, 2003
  4. Billy Patton

    MIME::Lite or /bin/mail help please

    Billy Patton, Nov 2, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    102
    Billy Patton
    Nov 2, 2007
  5. Replies:
    1
    Views:
    142
Loading...

Share This Page