>>>>> "HP" == Harry Putnam <rea...@newsguy.com> writes:

  HP> "Uri Guttman" <u...@stemsystems.com> writes:

  >> and yes, this is garbage code. there are many easy to use mail modules
  >> that will use sendmail or any available mail service for you.

  HP> With such a simple call to sendmail, is it still better to involve
  HP> extra modules as you suggest above.
  HP> Are these modules you mention easier to use than:
  
  HP>   open(SENDMAIL,"|$sendmail  $recip") or die "Can't open <$sendmail>: $!";
  HP>   print SENDMAIL $blob;
  HP>   close(SENDMAIL);

  HP> print SENDMAIL "$emailmsg\n";
  HP> print "$emailmsg\n";
  HP> }
  HP> close(SENDMAIL);

yes. it will be more portable (you have sendmail's path hard wired and
it varies). they can use other mailers (i have qmail). they can use smtp
directly to your isp's server (not calling a local server). they have
more options and are easier to understand. they don't use global
filehandles (well, you could use a lexical handle too.

  >> when you open a piped process, check the close as that is where you will
  >> actually find any errors from the open. since open | does a fork/exec,
  >> it can't tell you if the exec fails until you close the handle.

  HP> Not sure what you are suggesting to do there.  I mean other than ditch
  HP> the code in favor of a module.  Do you mean to put the `die' after the
  HP> CLOSE?

either is better. your code needs to check the close in case your open
to sendmail fails. and use a module instead for the whole thing.

  HP> Even without that though, wouldn't any errors at CLOSE still print to
  HP> stderr?

what errors? perl doesn't print system errors, it returns them in $!

here is a simple use of a module i like. note that it would be easy to
change the mailer if i wanted to. no need to know any quirks/syntax of
each mailer. also note the nice argument list of the headers.

#my $mailer = Mail::Mailer->new( 'sendmail', '/usr/sbin/sendmail' ) ;
my $mailer = Mail::Mailer->new( 'qmail' ) ;
#my $mailer = Mail::Mailer->new( 'smtp', 'Server' => 'outgoing.verizon.net') ;

        $mailer->open( {
                To      => $email,
                From    => 'u...@perlhunter.com',
                Sender  => 'u...@perlhunter.com',
                Subject => $subject,
                }
        ) ;

        print $mailer $body_text ;
        $mailer->close() ;

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to