Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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\" name@company.com<$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?

Comment on Using Mailx
Download Code
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\" name@company.com < output.txt";
    You could also open a pipe with
    open MAILX, "| mailx -s \"Testing Report\" name@company.com";
    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://20720]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-09-16 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (156 votes), past polls