[Linux-Discussion] Re: email message

  • From: John Madden <weez@xxxxxxxxxxxxx>
  • To: linux-discussion@xxxxxxxxxxxxx
  • Date: Fri, 26 Jan 2001 18:29:43 -0500

> # mail -s "message" -v addr@xxxxxxxxxx < file.txt
>
> but without using the redirection operator?

If you don't use the redirect, it'll expect input from stdin.  So, open a 
pipe to the message (assuming this isn't a shell script or something).  
For ex, in perl:

#!/usr/bin/perl
open(MAIL, "| /path/to/mailer");  
print MAIL <<EOM;
From: ...
To: ...
Subject: ...

<body>

EOM
close MAIL;

So you basically construct the email headers within the program.  I 
believe it's done the same way in C, but I've never tried it before.  You 
should be very careful to validate input on this, as you're piping to the 
system, and that can be bad, of course.

If you're doing it in a shell script, etc., you can pipe it in like this:

echo "all the stuff.... " | /path/to/mailer

..but it might be more complicated with carriage returns and whatnot.

John




-- 
# John Madden  weez@xxxxxxxxxxxxx ICQ: 2EB9EA
# FreeLists, Free mailing lists for all: //www.freelists.org
# UNIX Systems Engineer, Ivy Tech State College: http://www.ivy.tec.in.us
# Linux, Apache, Perl and C: All the best things in life are free!

=============================================================
Avenir Web's Linux Discussion List

List info: //www.freelists.org/cgi-bin/webpage?webpage_id=13
To unsubscribe: email linux-discussion-request@xxxxxxxxxxxxx
with 'unsubscribe' in the Subject line.

Administrative contact: weez@xxxxxxxxxxxxxx
=============================================================

Other related posts: