LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   getting To: from a file for sendmail or mailx? (https://www.linuxquestions.org/questions/linux-general-1/getting-to-from-a-file-for-sendmail-or-mailx-838122/)

MrUmunhum 10-14-2010 05:22 PM

getting To: from a file for sendmail or mailx?
 
Hi group,
I need to control sendmail or mailx from a file. The file will have the receprent as the first line, Subject: has the second line, etc. From what I can find with Google the only why to define the target and subject is on the command line?

Does any one know of a way to make a mailer use the data in a file??

The file would look like this:
Code:

me@mydomain.com
Testing
begin message
.

Thanks for you time.

tc1280 10-14-2010 07:03 PM

getting To: from a file for sendmail or mailx?
 
From the command line you could use head -n 1 <file> for the address and sed -n 2p <file> to send your file from the command line

KenJackson 10-14-2010 08:58 PM

Ah! Good point tc1280.

Assuming the file is named file,
the address is on line 1,
the subject is on line 2, and
the message body is line 3 to the end,
try this:
Code:

sed 1,2d file | mailx -s "$(sed -n 2p file)" "$(sed 1q file)"


All times are GMT -5. The time now is 06:00 AM.