Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to make a shell for sending mail

Status
Not open for further replies.

koeicjm

Programmer
Sep 12, 2001
73
JP
how can I write a shell to send a mail with subject and content , the default "mail" need to input the content and ended by ctl-d , so it is not I want , I want to fix the address, subject and its content at the shell file.
 
You can use mailx command for this purpose as example below

mailx -s &quot;Testing mailx commond&quot; surachal@dtac.co.th <<-EOF
Hello world :)

EOF
 
Actually, you should be able to do the same with mail (instead of using mailx):

mail -s &quot;Shell Generated Mail&quot; steview85 <<-EOF
Hello world :)
EOF

Note that &quot;EOF&quot; stands for &quot;end of file&quot;, but it is just a label here -- you can use another label if you prefer. The script reads as input (<<) until it hits the label indicated by the - and then passes a ctl-d (which is the true end of file - just like you do when you use the mail program interactively).

I don't know what you're trying to do, but knowing that ctl-d is the EOF mark gives you other options. You could write the content out to a file and then send that. Here's an example that demonstrates some possibilities:

rm -f mtmpfile
cat <<-EOF > mtmpfile
hello world :)
EOF
...
command >> mtmpfile
...
mail -s &quot;Mail from file&quot; steview85 < mtmpfile
rm -f mtmpfile

(Of course, you need to ensure you have permission to write to mtmpfile.)

- Steve StevieW85@go.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top