Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Using Mailx

by Anonymous Monk
on Jul 01, 2000 at 07:44 UTC ( #20720=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

In my perl script, I have following lines,
Format REPORT = Test . Sub one { open(REPORT,">output.txt"); write(REPORT); #trying to send mail using this output.txt file open(FILE,"output.txt"); system("mailx -s \"Testing Report\"<$FILE"); }
I am getting error message 'no message' when I execute the program. When I use this same mailx at the shell level, it sends the mail with the content in the file What I am doing wrong in the code?

Replies are listed 'Best First'.
Re: Mailx question
by QandAEditors on Jul 01, 2000 at 09:25 UTC
    You are using $FILE in your system() call, which you don't define, but you do have an open FILE, "<", "output.txt" right above it, so I think that you think that using $FILE at the end of the system command will use output.txt as the input, which is incorrect. The correct code would be
    system "mailx -s \"Testing Report\" < output.txt";
    You could also open a pipe with
    open MAILX, "| mailx -s \"Testing Report\"";
    and write to MAILX to bypass creating the file altogether.
Re: Mailx question
by QandAEditors on Jul 01, 2000 at 11:51 UTC
    The security-minded answer is "don't ever use mailx". It's a big security hole waiting to happen since you cannot disable tilde escaping.
      Tilde escaping is disabled as soon as mailx gets input from a "non tty". So if you pipe the input into mailx, tilde escaping should be off.
Re: Using Mailx
by Anonymous Monk on Sep 02, 2004 at 08:02 UTC
    try this:
    open MAIL, "| mailx -s '$Subject' -r ReplyAddress $MailAddress"; print MAIL $MailMessage; close MAIL;

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://20720]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2018-05-26 20:12 GMT
Find Nodes?
    Voting Booth?