Web page hosting and cheap domain registration service
  

 

Mailing Non-interactively: mhmail

[previous] [next] [table of contents] [index]

The Section Sending Files; Using mhmail and viamail had an introduction to mhmail. This section shows some examples of its uses in programming.

For instance, to mail a temporary file named $temp to the user who is running your Bourne shell script ($USER), your script could execute:

mhmail $USER -subject "XXX XXX" < $temp

Be sure to use a left angle bracket (<), not a right angle bracket (>). If the standard input (here, the file $temp) is empty, mhmail won't send a message. The workaround is to test the file size before running mhmail. If the file is empty, the echo command outputs a newline -- which is enough to make mhmail happy:

if test -s "$temp"
then mhmail $USER -subject "XXX XXX" < $temp
else echo | mhmail $USER -subject "XXX XXX"
fi

One more "gotcha": without command-line arguments, mhmail runs inc. mhmail was designed to be similar to the standard UNIX mail command. (With no addresses, mail gets your new mail.)

 

 

 

 

Cheap domains registrar | Buy domain name & domain registration | Domain registration 

Disclaimers: This document is provided as free service for the benefits of Active-Venture.com's web hosting customers only.

 
Quotes: The true measure of a man is how he treats someone who can do him absolutely no good.