When you log in to your system, you may see a notice that says "You have mail." Someone has sent you a message or document by electronic mail (email). With email, you can compose a message at your terminal and send it to another user or list of users. You can also read any messages that others may have sent to you.
Email has several advantages over paper mail: it's convenient if you're already logged in, it's delivered much more quickly, you can send it to any number of people almost as easily as to just one person, and the messages can be stored for later reference.
There are a lot of email programs for UNIX. Some UNIX systems have only an old, simple program named mail, which this book doesn't cover. Most UNIX systems have a Berkeley program called Mail (with an uppercase "M"), mailx, or just mail. A popular menu-driven program that's easier to learn is called pine. All programs' basic principles are the same, though. We'll cover the Berkeley mail program.
Your mail's recipient doesn't have to be logged in. The messages you send are stored in the recipient's "mailbox," a file deep in the UNIX filesystem (often located in the directory /usr/mail). Messages are kept there until the recipient logs in and decides to read them.
mail address1 address2 ...
There are several kinds of addresses, too many to explain here. If you have questions, see one of the references in Appendix A or ask your system administrator or postmaster (the person who maintains your email system). The most common addresses have this syntax:
username is the person's username and hostname is the name of their computer. If the recipient reads email on the same computer you do, you may omit the @hostname. To keep a copy of your message, just add your username to the list of addresses.
After you enter mail and the addresses, in most cases the program (depending on how it's set up) will prompt you for the subject of the message. Type a one-line summary of the message (just like a paper memo) and press [RETURN]. Type in your message, line by line, pressing the [RETURN] key after every line, just as you would on a typewriter. When you have finished entering text, type [CTRL-D] (just once!) on a separate line. You should get the shell prompt at this point - though it might take a few seconds. If you change your mind before you type [CTRL-D] you can cancel a message (while you are still entering text) by entering ~q (a tilde character, then the letter "q") at the start of a line. The cancelled message is placed in a file called dead.letter in your home directory. To see other commands you can use while sending mail, enter ~? (tilde question mark) at the start of a line of your message, then press [RETURN]. To redisplay your message after using ~?, enter ~p at the start of a line.
My trip to Chicago is on!
Alicia, I will be able to attend your meeting. Please send me the agenda. Thanks. ^D%
You can't cancel a message after you type [CTRL-D]. (Unless you're a system administrator and you're lucky to catch the message in time, that is.) So, if you change your mind about Alicia's meeting, you'll need to send her another message.
Let's read Jerry's message to Alicia:
2Message 2: Date: Tue, 4 Nov 1997 14:25:43 EST From: email@example.com (Jerry Peek) To: firstname.lastname@example.org Subject: My trip to Chicago is on! Alicia, I will be able to attend your meeting. Please send me the agenda. Thanks. &
qHeld 1 message in /usr/spool/mail/alicia %
When you start mail, it prints a "message header" that shows whether each message is "new" (N) or "unread" (U), a message number, the sender, and when the message was sent. A ">" marks the current message. You can read any message by entering its number; if you use a command without a number, the command acts on the current message. If you read a message and don't delete it, the message is automatically moved to a file called mbox in your home directory.
The output of mail says that the message was sent by Jerry on Tuesday, November 4, at 2:25 p.m. The ampersand (&) on the last line is the mail program prompt. Just as the UNIX shell prompt is a sign that the shell is waiting for you to enter a command, the mail prompt is a sign that the mail program is waiting for you to enter a mail command. Your mail prompt may consist of a single character. Learn the mail prompt on your system and enter one of the commands in Table 3.2. For instance, Alicia might have chosen to enter r to reply to Jerry before using d to delete his message.
|?||Display menu of mail commands.|
|#||Show message number #.|
|n||Display the next message.|
|p||Display current message.|
Delete the message. Messages you read and don't delete are saved in mbox.
Mail a message to the addresses addrs.
|r||Reply to sender of current message.|
|R||Reply to sender and other recipients of current message.|
|s file||Save a message in the named file.|
|file file||Handle the messages in the named file.|
|file %||Handle the messages in your system mailbox.|
|h||Display summary of messages.|
|q||Quit the mail program.|
Exit the mail program, ignoring any changes you made during this session.
You can practice sending mail to your friends in this exercise. List the users logged on to the system and choose a name. You can also use your username to send mail to yourself. Enter the following message. Do not forget to press the [RETURN] key at the end of each line, and type [CTRL-D] on a line by itself when you're done.
|List logged-on users.||Enter |
|Send mail to someone.||Enter |