in reply to Re: sendmail close error
in thread sendmail close error

I am not sure I understand what you suggest but
print "Mail sent.\n";
is working

Replies are listed 'Best First'.
Re^3: sendmail close error
by Marshall (Canon) on Jul 20, 2011 at 21:56 UTC
    What we have is the sequence
    1. open MAIL pass
    2. print MAIL ????
    3. close MAIL fail
    step (1) succeeds, step (3) fails. The natural question is did step (2) fail or succeed? I've never seen close on a pipe fail, but it does in this case. I've never seen a print to an open pipe fail either. But, since we are into rare, weird stuff, just curious about the print to the MAIL pipe. print() returns status just like open() or close(). I admit to being stumped. This might tell us something surprising or not - but its easy to do.

    print MAIL ...... or warn "print to MAIL failed".

    Other way to code:

    #!/usr/bin/perl -w use strict; my $status = print "this is a test\n"; print "first print returned $status\n"; __END__ output: this is a test first print returned 1
      That's what I did:
      print MAIL "From: $from\n"; print MAIL "To: $to_ad\n"; print MAIL "Subject: $subject\n\n"; my $stat = print MAIL "$message"; print "Mail Status: $stat\n"; close(MAIL) || warn "Error closing mail: $!"; print "Mail sent.\n";
      I got: Mail Status: 1
      Mail sent.

      But the mail still does not reach my box and the log reports "Error closing mail:"
        Interesting - I was sort of suspecting that because the most common suspect for error (non-existent reader) would cause a SIGPIPE and you'd get different symptoms. I uploaded this code to a Linux box so I could play with it. Your code works fine on that machine verbatim. I haven't been able to come up with a scenario to force this close() error to happen. Sorry - I'm stumped. Maybe your system admin can shed some light on this?