Home > Help Files > Email > Mail Program

Unix Mail


                         Using the Mail Program

                              Jan 22, 2001


The UNIX "mail" program is a general purpose utility for transmitting information (letters, files, etc.) from one user to another. It can be used between two users on the same machine, or from a user on one machine to a user on another machine. It can also send messages to groups of people, and to files, which can serve as a sort of "transcript" of what has taken place.

GENERAL USAGE To send mail to another user, the general form is: % mail user Your message goes here with as many lines as you need. <Control-D> In the above example, "%" is the UNIX prompt, and the name "user" would be replaced by the name of the account you want to send mail to. The message goes under it, taking as many lines as you need; be sure to press return at the end of each line. Finally, the "" means to hold the "control" or "CTRL" key down and press the "D" key. This tells "mail" that you are done with your message and you would like it sent. A typical message might be something like this: % mail phil Phil, Can you meet me for lunch tomorrow outside of Etcheverry? Doug <Control-D> SENDING MAIL TO USERS ON OTHER MACHINES The above example works only if "phil" has an account on the machine you are currently. What would you do if, for example, you were on Tycho and you wanted to send a message to a friend who has an account on Newton? Simple -- just type % mail yourfriend@newton (pronounced, of course, "yourfriend at Newton"), where "yourfriend" would be the name of your friend's account on Newton. The mail program is smart enough to figure out how to get to Newton and route the mail there. RECEIVING MAIL When you log in, if anyone has sent you any mail, the system will tell you with the message "You have mail." If this is the case, when you get to the system prompt ("%"), you should type % mail with no name after the "mail". This tells mail that you want to read any messages you may have, and that you don't want to send any right now. If you were to have three messages, and your name were to be "phil", you might see something like this: Mail version 2.18 5/19/83. Type ? for help. "/usr/spool/mail/phil": 2 messages 2 new >N 1 me128-al Sat Feb 4 14:55 11/281 "Meet me for lunch" N 2 root Sat Feb 4 14:56 14/312 "Help files" N 3 jlapsley Sat Feb 4 14:57 18/543 "Sample message" The "Mail version 2.18..." line is simply "mail"'s way of telling you that you are now in "mail". "/usr/spool/mail/phil" is the name of the file that "phil"'s messages are stored in; the "phil" will be replaced with your login name. "2 messages 2 new" is "mail" telling you that you have 2 messages, both of which you have never seen before. The next three lines are a brief summary of the three messages. The "N" means that the message to the left of the "N" is "new". The number to the left of the "N" is the number of the message when you refer to it with commands (below). Next is the name of the sender, the date the letter was received, the size in lines and characters (11/281 means 11 lines, 281 characters), and the subject of the message, if any, in quotes. Finally, you will be at the command level of the "mail" program; you can tell this by its prompt, which is an ampersand (&) with the cursor to the right of it. IF YOU HAVE NO MAIL As a special case, you may sometimes type "mail" from the shell and be informed that you have no mail by the following message: Mail version 2.18 5/19/83. Type ? for help. "/usr/spool/mail/phil": 0 messages No mail You will then be put back at the command level of the shell, with the "%" prompt. READING A MESSAGE To read a message from the mail program's prompt, simply type in the message number. For example, to see message number 2, you would say 2 REPLYING TO A MESSAGE Once you are finished reading a message, there are several things you can do with it. First, you can "reply" to it, which simple shoots off a response to whoever sent the message to you. The "mail" program will tell you who the message is being sent to, and make the subject "Re:" followed by whatever the old subject of the message was. For example, if I had a message from "fred", with a subject "Lunch tomorrow?", if I replied to the message, I would see "mail" print the following: To: fred Subject: Re: Lunch tomorrow? and I would then be able to type a response and press <Control-D> when finished. DELETING A MESSAGE After you have replied to the message, or even if you haven't replied to it, you can "delete" it from your mailbox. You can do this by typing "d" followed by a space and the message number (e.g., "d 1"), or by just typing "d" and hitting return, which tells "mail" that you want to delete the last message you did anything with. UNDELETING A MESSAGE If you realize that you didn't want to delete that message, and that you'd like it back, "mail" is forgiving. Just type "undelete" (or just "u") followed by a space and the message number (e.g., "u 3"). This will restore the previously deleted message in question. Like all commands, just typing "u" and hitting return will un-delete the last message you did anything with. IGNORING A MESSAGE If you would just like to ignore a message, you can simply press return without any command, which tells "mail" to display the next message. SAVING A MESSAGE If you would like to save a copy of a message in a file before deleting it from "mail", you can use the "save" or "write" command to save it. The format is "write", followed by a space and a message number, followed by a space and the name of the file you want it written to. If you don't specify a message number, if assumes that you are referring to the message you last accessed. That is, write 1 fred.txt (or) save 7 foobar (or) write frobbage (which writes the current message to the file "frobbage") The difference between "write" and "save" is that "write" removes some of the header information (i.e., "Date:", "Received-By", etc.), while "save" saves the message verbatim. SENDING MAIL FROM INSIDE THE MAIL PROGRAM When you are at "mail"'s prompt (&), you can type "mail" (or just "m") followed by a space and a login-name of a user you want to send mail to. After that, it's just like you typed "mail user" from the shell (i.e., the "%" prompt), and you should follow up with your message and a <Control-D>. When you have finished sending the message, you will be dropped back to the "mail" program's prompt. SEEING WHAT'S LEFT After you have deleted several messages, it often is nice to see what is left. This can be accomplished by the "header" (or "h") command, which shows the initial brief information for the remaining letters. Actually, "mail" knows what message number you are on, and will only show you the headers of messages within a certain "distance" of your position. For example, if you have 50 messages, and you are currently at message number 10 (i.e, that was the last message you did anything with), if you type "he", you would only see a few messages past number 10, and certainly not all 40 others. PRESERVING MESSAGES Messages that you have read but not deleted are automatically stored in the "mbox" file in your home directory. To prevent a message from being moved to the "mbox" file, you can type pre QUITTING When you are finished with the "mail" program, and you have read or replied to all your messages, you can type "q" to exit back to the shell. Any messages you have "d"eleted will be gone permanently at this point, and the "undelete" command won't be able to bring them back. Messages which you have read but not deleted will be stored in a file "mbox" in your home directory. Messages which you have not looked at will be preserved until the next time you type "mail". QUITTING WITHOUT CHANGING MESSAGE STATUS If you want to quit the "mail" program without it deleting the messages you deleted, moving the message you read to your "mbox", you can type "x". MORE HELP This document should have given you a *very* basic knowledge of the "mail" program. If you are in "mail" and want more help, you can just type "?" for a refresher list of commands, some of which have not be explained in this document. For more information on some of the more "tricky" aspects of the "mail" program, you can examine some of the following help files. To get help on the subject listed on the right, type the command on the left: Command Subject ---------------- ----------------------------- help mail alias How to avoid typing long login- names and send mail to groups of people under one name. help mail forward How to have your mail automatically forwarded to another address. help mail mailrc How to install a ".mailrc" file in your home directory to tell "mail" to do or not do certain things automatically. help mail networks How to send mail to people on other machines at Berkeley. help mail tilde How to use the tilde (~) commands when sending mail, which allow editing mmessages, setting subjects, etc. THE MANUAL For a very comprehensive and well written explanation of "mail", covering all its useful and useless options, you might want to pick up a copy of the "Mail Reference Manual" by Kurt Shoens, available from the Computing Services Library, 218 Evans Hall. IF YOU HAVE QUESTIONS If you have any specific questions, please mail them to the account "help". That is (and you should know how to do this by now): % mail help Your questions <Control-D>

 


Comments to consult@newton.berkeley.edu
© 1998-2009 UC Regents