USING MAIL FOR AUTOMATIC MESSAGING

We all have our favorite e-mail clients, and the new features included in recent ones have made messaging over the Internet an unanticipated pleasure to those who used it 10 years ago. Still, there's something to be said for the originals. For one thing, new e-mail clients often have too many features and are unable to easily perform simple automatic tasks. Also, most e-mail clients in use today have GUIs, which make them even more difficult to use in an automatic fashion.

One of the first mail clients, simply called "mail," was used as far back as version 6 of AT&T UNIX. Today, most Linux systems also come with /bin/mail, as it's fondly called. Although using /bin/mail as an e-mail client would be an exercise in frustration and futility, it does have the ability to automate some messaging that you may require. For instance, suppose that you want to send yourself a reminder message every day. You could manage the scheduling using cron or at, but how do you send the actual e-mail? You can do this easily using /bin/mail. Here's an example:

# echo "Time to go home." | /bin/mail -s "Time to go home" rick

This will send a message to the user, named Rick, with a subject of "Time to go home." Since /bin/mail takes standard input as the message itself, the text we echo is the body of the message. In this case, it's "Time to go home." Likewise, to automate a message to a mailing list, we might use:

# /bin/mail -s "Rules of the list" mylist@domain.com <~/rules.txt

This sends the message to mylist@domain.com with a subject of "Rules of the list." The message body is the contents of the file ~/rules.txt.

With /bin/mail, the sender's e-mail address is always the name of the user you are logged in as with the hostname of the machine you are logged in to.