Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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]
[shmem]: man perlfunc |perl -nle '$ok++ if /Alphabetical Listing of Perl Functions/;if($ok ){$s{$1}++if /^ (\w+)/}}{for(keys %s){$f="prototype \\\&CORE::$_"; eval"$f"||delete $CORE::{$_}}print for sort keys%CORE::'
[shmem]: well, there are some builtins which don't have a prototype...
[Discipulus]: eh eh.. i was looking in toke.c but dunno if is already used
[shmem]: oh the whitespace in the regex got condensed, meh
[shmem]: should be /^ {7}(\w+)/ or such
[shmem]: least for my perldoc on Linux debian 8
[Discipulus]: mmh.. at themomemt i just an old 5.8 and outputs just GLOBAL::

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (8)
As of 2017-05-23 10:08 GMT
Find Nodes?
    Voting Booth?