1.3. The Unix mail command

The Unix mail command is described here. This is one of the oldest programs for accessing email, and it shows its age. I don't know anyone who actually uses this to read their normal email. It is worth knowing, though, because it can be used entirely from the command line with no interaction. This makes it useful when writing scripts, where you might want to automatically send an email as part of a programmed action. For example, I have a script that runs automatically every night to rebuild the tables used by the Search command on the course website. If something goes wrong, it sends me an email with the relevant error message.

Sending

To send mail to someone with e-mail address addr, give the command

   mailx addr

For example, you could send me mail via the command

   mailx zeil@cs.odu.edu

Although, if you are logged in to a CS Dept machine and want to send me e-mail you could just say

   mailx zeil

After you have given the mail command, you will be prompted for a subject line to indicate what your message is about. After that, you begin typing your message on the next line. When you are done, type ^D on a line by itself. You will then be prompted with Cc: , which allows you to add the login names of other people to whom you would like to send a copy of your message. (Many people like to make a habit of cc'ing a copy to themselves.) If you do not want to send any extra copies, just hit the Return key. Your message will then be sent.

As you type your message, you can send special instructions to the mail program by entering any of the following at the start of a line:

~e

Enter the editor named by the EDITOR environment variable. This is a good way to correct mistakes made on previous lines.

~r filename

Insert the contents of a file into your mail message.

~p

Print the message as it appears so far.

~m #

If you are actually replying to a mail message that you received (see Receiving, below), this inserts the text of mail message number # into your reply.

Receiving

When you first log in, you will be informed if you have received e-mail. At that time, or anytime thereafter, you can use the frm command to list the messages awaiting.

To actually read your mail, give the command mailx with no arguments. You should see a numbered list of your messages. If not, the command h (for headers) will list them. You can then read a message by typing it's number.[31]

After reading the message, you can take any of several actions:

r

Send a reply to the author of the message you just read.

R

Send a reply to the author of the message you just read and to anyone in the Cc: list of that first message.

dp

Delete this message and move on to the next (if any).

n

Move on to the next message.

s filename

Save a copy of this message in the specified file. If the file already exists, the message is added to the end.



[31] If you have no messages at the moment but would like to practice reading mail, try following the earlier instructions to send yourself a couple of messages. Then just wait a few minutes until frm indicates that your messages have arrived.