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

Hey all, Can anyone tell me where I am going wrong in the following?
#!/usr/gnu/bin/perl -w # # use strict; no strict "refs"; use Mail::Sender; my $f2dir = "/home/bradley/scripts/prog/names"; my @names = <$f2dir/*.f2mail>; my $file; foreach $file (@names) { if ( (! -d $file) && ($file =~ /\b\.f2mail/) ) { parse_mail($file); print "."; }else{ print "Error with $file, $!"; } } ###################################################################### +########## # Begin Subroutines # # parse_mail parses the parameter file (*.f2mail) and submits the resu +lts to # Mail::Sender for smtp ###################################################################### +########## sub parse_mail { my $mail = "@_"; open (MAIL,$mail) || die "Cannot open $mail, $!"; my @mailf = <MAIL>; chomp (@mailf); close (MAIL) || die "Cannot close $mail, $!"; sender_mail(@mailf); } ###################################################################### +########## # # sender_mail calls the Mail:Sender module and prepares for smtp ###################################################################### +########## sub sender_mail { my @mailf = @_; open (BODY,$mailf[3]) || die "Cannot open $mailf[3], $!"; my @body = <BODY>; close (BODY) || die "Cannot close $mailf[3], $!"; rename($mailf[4],"$mailf[4]\.txt") || die "Cannot rename $mail +f[4], $!"; my $sender; ($sender = new Mail::Sender ({ from => $mailf[2], smtp => 'localhost'})) || die "Send +er error: $sender, $Mail::Sender::Error!\n"; ($sender->MailFile( {to => $mailf[0], subject => $mailf[1], msg => "@body" +, file => $mailf[4]})) || die "Sender error, $sender, $Mail::Sender::Error!"; }
I run it, and everything seems to go fine, but I get no mail. My syslog also shows no record of a mail being submitted. Any help anyone could provide would be greatly appreciated. I'm also looking for some info on my coding... any suggestions on making it better? Thanks in advance, Bradley
Where ever there is confusion to be had... I'll be there.

Replies are listed 'Best First'.
Re: Mail::Sender question... again
by ryddler (Monk) on Jun 29, 2001 at 07:40 UTC

    Everything seems fine, but with a failure your call to $sender->MailFile(...) should be returning an error code which will evaluate as true. Therefore your die "Sender error, $sender, $Mail::Sender::Error!" won't execute.

    If Mail::Sender is successful it should return a reference, so what you should do to test for failure is wrap the call like this:

    ref ($sender = new Mail::Sender ({from => $mailf[2], smtp => 'localhos +t'})) || die "Sender error: $sender, $Mail::Sender::Error!\n"; ref ($sender->MailFile({to => $mailf[0], subject => $mailf[1], msg => +"@body", file =>$mailf[4]})) || die "Sender error, $sender, $Mail::Sender::Error!";
    This should catch your errors for you...

    ryddler
      ryddler, Thanks, that did the trick. Works fine now. Bradley
      Where ever there is confusion to be had... I'll be there.