UNIX allows you to use electronic mail to communicate with anyone on your system. If you are connected to the Internet, you can also use the UNIX mail programs to send e-mail to any e-mail address. This chapter covers only the simplest uses of e-mail. For a full discussion of e-mail in the UNIX System, including coverage of graphical mail applications, see Chapter 8.
A basic mail program is mail. Most systems also include an enhanced version of mail called mailx, or sometimes Mail. All three of these applications work in pretty much the same way This chapter will use the command mailx in the examples, but if you get an error message when you try to run mailx you can use Mail or mail instead.
It is easy to use mailx for simple tasks, such as reading and replying to mail messages, but doesn’t provide many advanced features (for example, it is very hard to send attachments in mailx). Although you will probably switch to a more complex mail program once you are comfortable using UNIX, mailx makes a good introduction to using e-mail on the UNIX System.
When new mail arrives, you are notified by a simple announcement that is displayed on the command line.
$ You have new mail
This message is displayed when you first log in, if you have mail that has been delivered since your last session. It can also show up when the prompt is printed, after you enter a command. If you haven’t entered a command recently, you can press ENTER to see if you have new mail.
To view your messages, just type the mailx command, like this:
$ mailx Mail version 8.1 6/6/93 Type ? for help. "/var/spool/mail/raf": 8 messages 5 unread >U 1 corwin Tue Oct 24 09 15 21/857 "concert this weekend" 2 nate@engineer.com Tue Oct 24 11 23 29/930 "interesting math prob" U 3 liz@thebest.net Wed Oct 25 23 10 234/10953 "Online Gaming Article" N 4 dkraut@bio.ca.edu Fri Oct 27 02 27 16/733 "Re: lunch next week?" N 5 rlf@library.edu Fri Oct 27 12 08 83/2558 "flight info" N 6 etch Fri Oct 27 13 25 15/629 "Meeting" N 7 dbp Fri Oct 27 13 27 16/634 "Re: Meeting" N 8 nate@engineer.com Fri Oct 27 17 05 20/812 "Re: dinner plans" ?
The mailx program will show you each message as a one-line heading with the following structure:
A single character that tells you the status of the message: N for new messages, U for unread messages (messages whose headers have been displayed before, but that you haven’t yet read), and O or a blank space for old messages (messages you have read before).
The message number.
The date and time of delivery.
The size of the message, in lines and characters.
The subject of the message.
The current message is marked by a carat (>).
After this list, you will see a ? or & prompting you to enter a mail command. To see a list of all the commands you can enter, type in a question mark.
To read the current message, type p (for print) or t (for type). To read the next message, press ENTER or type n (next). To read other messages, type the message number, as in
? 4 Message 4: Date: Fri, 27 Oct 2006 02:27:42 −0700 From: D Kraut <dkraut@bio.ca.edu> To: raf@turing.ca.edu Subject: Re: lunch next week? Panda Cage sounds great. See you Tues.
If a message is very long, you may have to press the SPACEBAR to make it scroll. After viewing a message, you can type h (header) to display the list of messages again.
To delete the current message, type d. To delete any message, type d followed by the message number. You can delete several messages at once by entering a range:
? d 5–7
To restore a message, type u (for undelete) followed by the message number (or by a range of message numbers).
The command to save the current message is s followed by the name of a file to save it to. You can specify the message or messages to save by including the message numbers. So, for example,
? s 2 savemail
saves message 2 in the file savemail. To view the messages you have saved in this file, type
$ mailx -f savemail
from the command line.
To send a message, you use the mailx command with the address of the recipient as an argument. If you are sending mail to someone on your system, you can simply use the person’s login name as the address. The command
$ mailx dbp
tells mailx to deliver the message to user dbp on your system. To send mail to someone via the Internet, you have to enter their full e-mail address, as in
$ mailx etch@lpl.net
This will only work if your system is configured correctly See Chapters 8 and 17 for more details about sending remote mail.
If you are already in mailx, you can send a message by typing m followed by the address at the prompt:
? m smullyan@logic.indiana.edu
To send mail to many users at once, type all of the addresses separated by spaces.
After you enter the address, mailx will prompt you for a subject and then allow you to type in the body of the message. After you are finished, tell mailx to send the message by entering a line that contains only a single period.
$ mailx rlf@library.edu Subject: checking in Thanks for taking care of Kili while we're gone. I left a salad in the fridge for you. See you next week! . $
If you prefer, you can use CTRL-D instead of the period to terminate your input and send the message. To cancel a message without sending it, type CTRL-C (you may have to enter it twice).
The mailx program also enables you to reply to messages. To reply to the sender, type R. This takes the address from the current message and puts you into message creation mode. To include all the recipients of the message in your reply, type a lowercase r, instead. On some systems, the system administrator may have switched these two commands, so that R replies to all recipients. Be sure to check which addresses have been included in your mail before you send it.
To quit the mailx program, type q at the prompt. Any messages that you have read will be moved to the file mbox. To keep messages in your inbox, type the command pre followed by the message numbers before quitting mailx.
To exit without saving any of your changes, type x.