Dalin has asked for the wisdom of the Perl Monks concerning the following question:

Hello everyone. I am trying to do some automatic emailing of files using the Mail::Sender module. Whenever I invoke the script (using -w), I get an error stating: Unsuccessful stat on filename containing newline at /usr/gnu/lib/perl5/Mail/Sender.pm line 759. I have checked the Sender.pm file and find no newline character. I'm pretty new to the whole Perl thing and this is my first outing to try and write something usefull. If anyone has anything, please let me know. Thank you very much in advance. Bradley

Replies are listed 'Best First'.
Re: Mail::Sender trouble
by bikeNomad (Priest) on Jun 05, 2001 at 23:43 UTC
    Is it possible that the filenames you're passing it have newlines in them? I'm not using Windows, so don't have Mail::Sender, but if you read them from a file, you may have to remove the newlines:

    open FILES, 'listOfFiles.txt'; while (my $file = <FILES>) { chomp($file); # may need this send($file); # or whatever }
Re: Mail::Sender trouble
by cacharbe (Curate) on Jun 05, 2001 at 23:47 UTC
    Do you have an example of the code that is causing the problem? That is, can you recreate the problem with a small amount of code?

    Look at the Writeup formatting tips node and let's see what you have either way.

    C-.

      Here is my code. Like I said, this is my first stabb at something usefull, actually my first time period. The print statement that is printing all of the variables before they are passed to the subroutine is there just so that I could see what was actually being passed on to the sub. The "address.mail" file is a flat, array type file with one entry per line. Here it is:
      #!/usr/gnu/bin/perl -w use Mail::Sender; $mail = "address.mail"; # flat file passed from another program if (-e $mail) { open (FILE,$mail); @mailf = <FILE>; close FILE; $addr = $mailf[0]; # assigning mail variables $subj = $mailf[1]; # in the order that they $from = $mailf[2]; # are in the file $body = $mailf[3]; $attach = $mailf[4]; print "$addr\n $subj\n $from\n $body\n $attach\n"; sender_mail($addr,$subj,$body,$attach); } } sub sender_mail { ref ($sender = new Mail::Sender ({ from => '$addr', smtp => 'my.mailhub.com'})) # have to + be carfull with the hostname. || die "Mail::Sender::Error, $!"; (ref ($sender->MailFile( {to =>"$addr", subject =>"$subj", msg =>"$body", file +=> "$attach"}))) }

      Edit: chipmunk 2001-06-05

        You should put <code> tags around it. Anyway, you're reading the file into @mailf, but each of the lines have newlines at the end. Including your filename. Instead, you may want to do this:

        open(FILE, $mail); @mailf = map { chomp; $_ } <FILE>; close(FILE); # now process $mail[n]

        update: fixed map. Actually you could just go:

        @mailf = <FILE>; chomp(@mailf);