in reply to can't get mailx to send from within a script

Doesn't mailx need some input on it's STDIN, like the message for instance? I think you need to do something like (untested) :

open MAILX,'|/bin/mailx -s "hello" john@work.com' or die $!; print MAILX 'Your message here'; close MAILX or die "mailx: $! $?";

I would however recommend using another mechanism to send mail in your program, not limited to piping directly to sendmail or using a module such as Email::Send

/J\

Replies are listed 'Best First'.
Re^2: can't get mailx to send from within a script
by Adrian (Initiate) on Aug 17, 2006 at 13:51 UTC
    Gellyfish,

    not sure why the other suggestions didn't work, but yours did so that's what I went with.

    As it happens I needed to email the contents of a file and found this to work :

    $file="/tmp/output.txt";

    my $text = do { local( @ARGV, $/ ) = $file ; <> } ;

    open MAILX,'|/bin/mailx -s "Output" John@work.com' or die $!;

    print MAILX $text;

    close MAILX or die "mailx: $! $?";

    many thanks to all who contributed, Ad