|
| 以 PDF 格式下載這本書 (736 KB)
Chapter 7 Using MailSunOS provides a program called mailx for sending and receiving electronic mail (email). mailx provides features for reading, writing, sending, receiving, saving, and deleting messages. The mailx program is not window based, and can therefore be run on any terminal. Although you might prefer to use the window-based mail, you might find that the mailx program is handy when you are dashing off a quick note. Also, if you want to set up your own mail aliases, you can read about it here. Note – If you are in a window environment and the Mail Tool icon appears on your screen, quit from the Mail Tool before trying the examples in this chapter. Otherwise, you will have two mail processes active, and these concurrent processes might generate error and warning messages. You can safely send mail messages in a Command Tool or Shell Tool window, but if you read your mail and save or delete messages, this affects your “in tray,” thus confusing Mail Tool. mailx BasicsThis section describes how to perform basic tasks in mailx. Later sections describe features and functions that can enhance your ability to use this program. An intended recipient's login name and machine name serve as a unique address for the mailx program. If the intended recipient is on the same machine as the sender, the login name is all that is required. Each user has a mailbox in which to receive mail. This mailbox is generally located in the /var/mail/username directory, where username is your login name. The mailx program notifies you when you receive mail and places the mail in your mailbox. After you read your mail, mailx automatically places these messages in a storage file called mbox, which is also located in your home directory. Starting mailxStart mailx by typing the following command at a prompt and then pressing the Return key:
If you don't have any mail waiting for you, your terminal displays the message:
In this message, username is your login name. Sending Yourself a Sample MessageTo see at a glance how mailx works, you can begin by sending yourself a sample message. At the prompt, give the mailx command again, but this time include your address (your login name plus your machine name). For example, if your login was rose and your machine name was texas, your address would be rose@texas. (The @ symbol is read as “at.”) You might be able to use just your login on a local network—consult your system administrator when in doubt.
The program responds with a Subject: line:
If you like, type a word or two here about the content of the message you're sending yourself and press Return. Now type the body of the message. Use short lines and press Return at the end of each line. Note that you can only make corrections as you go by moving back a space and retyping lines before you press Return. Your sample message might look something like this (the spaces between lines are made by pressing Return twice):
To send your sample message, press Return to complete the last line of the message and then press Ctrl-D. After your message has been sent, the system returns a command prompt. Reading Your Sample MessageTo read your sample message, use the mailx command again. Your screen should look something like this:
The first line identifies the version of mail that you are running. The second line indicates your mailbox, usually located in /var/mail/username, where your incoming mail is deposited. The third line in this example is the header of the message you sent yourself. The “N” at the beginning of the line means that it's a “new” message. A “U” (unread) means the message was new, but was not read before quitting the mailx program previously. The information in this screen is discussed in greater detail in Reading Messages. Every message is assigned a number as it is received: Rose's message to herself is shown as message number 1. To read a message, type an ampersand (&) and the message number at the mailx prompt, as follows: Quitting mailxWhen you have finished your work in mailx, you can quit the program by using one of two commands: q (quit) or x (exit). If you type q at the mailx prompt and then press Return, you see a message similar to the following:
In this message, home_directory is the path name to your home directory. When you use q to quit mailx after reading messages, mailx moves the messages from your mailbox and saves them in the mbox file in your home directory. mailx also saves any changes or deletions you've made. If you type x at the mailx prompt and then press Return, the mailx program does not save any changes or deletions, nor does it move any messages you've already read into the mbox file. Reading MessagesIf you have mail, mailx notifies you each time you log in with the message You have mail or You have new mail To read your messages, type mailx at a command prompt and press Return. If no mail is waiting for you, you will see the message: No mail for username Otherwise, you see a list similar to the following:
The mailx program displays information about itself (version number and date) and instructions for getting help (Type ? for help). On the next line, mailx specifies the location of your mailbox, the number of messages received, and their status. Next, mailx shows a numbered list of the messages in your mailbox. From left to right, the columns in each line specify:
When you have several messages in your mailbox, the displayed list might not show all of your mail. If this situation applies, type: To view the current message in the mailbox list (marked with >), press Return. Press Return again to display the next message. To read any message in the list, type its number and press Return. Deleting (and Undeleting) MessagesAfter you have read a message, you might decide to delete it rather than save it to your mbox file. A save to the mbox file is the default when you quit the mailx program. To delete the last message you read, just type d at the mailx prompt. To delete a specific message from your mailbox, use the command form: d number For example, to delete the second message, use this command from within mailx:
You can also delete several messages at a time. To delete messages 1 and 3, use the command:
To delete a range of messages, for example 1 through 3, use the command:
Before you quit mailx, you can undelete messages you've removed from your mailbox. Use the command form: u number followed by Return. For example, to undelete the second message, use this command:
To undo your last deletion, just type u at the mailx prompt immediately after the deletion. For example, if your last deletion command was d 2-5, type u to undelete messages 2, 3, 4, and 5. Note that all deletions are made permanent when you quit mailx with the q command. That is, you can no longer undelete messages that have been deleted. You can, however, quit mailx with the x command and leave your mailbox intact. As mentioned previously, if you quit with x you leave read messages marked with a U, deleted messages undeleted, and so forth. Printing MessagesYou can print a hard copy of a message by piping a message to a printer command. To do so, use the following command form at a mailx prompt: |number lp The | symbol is called a pipe. For example, to print a copy of message 2, type:
Then press Return. If a message number is not specified, mailx pipes the current message to the printer. For more information on piping, see Redirecting and Piping Command Output. Sending MessagesTo send mail with the mailx program, you need to know the login name(s) of the intended recipient(s) of your message. If an intended recipient is on a different machine, you also need to know that user's machine name. To determine this information, you can use the who, finger, or rusers commands. Type the who command to list all the users who are currently logged in to the file server you are on. The displayed list contains users' login names, their terminal types, and the date and time they logged in. For example:
Type the finger command to display the same type of information as who with more detail. The information that appears depends on how your system administrator has set up this command. As an example, you might see something like the following:
The rusers command provides information on the users who are currently logged in to your local network. Refer to Chapter 9, Using the Network for instructions on the use of the rusers command. When you have determined the necessary user information, complete the following steps to send a message.
Undeliverable MessagesIf you specify an incorrect user address when you send a message, the system responds with the message user@machine...User unknown The message is then returned to your mailbox. The next time you type the mailx command, the header states that you have returned mail, similar to the following example:
When a message cannot be delivered, the file is also copied to a file in your home directory named dead.letter. Canceling an Unsent MessageYou can cancel a message at any time before it is sent by pressing Ctrl-C twice. Adding Carbon and Blind Carbon CopiesBefore sending a message, you can specify that “carbon copies” be sent to other than the main addressees. You can also send “blind carbons.” This specification ensures that recipients of your message can read the addresses for the carbon copies, but not the addresses for the blind carbons. Many people send themselves carbons or blind carbons in order to retain a copy for their own record. You can use three methods for sending carbon copies with a message:
Inserting a Copy of a Message or FileYou can insert a copy of any message in your mailbox into the message you're writing. Likewise, you can insert a copy of any text file. Inserting a MessageUse the following command form to insert a message.
In this example, number is the number of the message to be inserted. For example, to send to another user a message that includes a copy of message number 3 from your mailbox list, complete the following steps.
Inserting a FileYou can also insert a copy of any text file into a message. As you are writing a message, use the following command form.
For example, to insert the file outline in the current message, type the following command.
Replying to a MessageReply to mail at a mailx prompt by typing the following command. r number If you omit the message number, mailx replies to the current message. For example, to reply to the sender of message 2, type the following command.
mailx automatically addresses your message and supplies an Re: Subject: line that echoes the original Subject: line. Send your reply as you would with any other message. R is a variant of the reply command that sends your reply to all recipients of the original message as well as to its sender. Use this command only when absolutely necessary, to avoid generating “junk mail.” Note – You can insert a message into your reply as shown in the previous section. To insert a copy of the message to which you are replying, type the command ~m without a message number. Saving and Retrieving MessagesIn addition to sending and receiving messages, you might also save and retrieve them for later use. In mailx you can save messages by appending them to regular text files. You can also append messages to special files called folders. Both methods are discussed subsequently. mailx makes a distinction between saving messages and copying them. Saving removes a message from the mailbox and appends it to a file or folder. Copying leaves a message in the mailbox and appends a copy to a file or folder. Saving and Copying Messages in FilesTo save a message into a file, use the following command form at the mailx prompt.
where number is the number of the message to be saved and filename is the file where you want to save the message. For example, to save message 3 into a file called ~/notes/finance, you would type:
Remember that in a path name, the ~ represents your home directory. You can also save several messages at once to the same file. For example, to save messages 3, 5, 6, 7, and 8 to ~/notes/finance, type the following command.
If the file you specify does not exist, mailx creates it. If the file does exist, mailx appends the message you are saving to the end of the file. Saving a file removes it from your mailbox. mailx displays an asterisk (*) next to the header of any message than has been saved. To leave the message in your mailbox while appending it to another file, use the copy command, as follows:
Saving and Copying Messages in FoldersYou can avoid typing full path names to files if you save or copy messages to mail folders. Folders are special files that are stored in a folder directory. The advantage of saving or copying messages to folders is that your messages are automatically stored in the same directory, where they are easily accessible without typing long path names. Setting the Folder DirectoryTo use folders, you must first set up a folder directory. Follow these steps to set up a folder directory.
Now your folder directory is set to receive messages that are saved in folders. The change to the .mailrc file becomes effective the next time you start mailx. Designating FoldersYou use the same commands to save or copy messages into folders as into files, except that the folder name is preceded by a plus sign (+) instead of a path name. The + tells mailx that the folder is to be kept in the folder directory (Messages). For example, to save message 3 to a folder called projects, type:
mailx interprets this command as “save message 3 into ~/Messages/projects.” If the folder doesn't already exist, mailx creates it. Copy the message into a folder by typing:
Sending a Message Directly to a File or FolderYou can send copies of your messages directly to one of your files or folders. To send a copy to a folder, simply type the folder name in either the Cc: or the Bcc: field. Sending a copy to a file is similar, but you must include the full path name. Reading Messages in Files and FoldersTo read messages that are saved in a file, use the command form:
In the previous example, you would read the file ~/memos/finance by typing:
You can read messages that are saved in a folder with a similar command—just use the + instead of a path name. For example, to read the messages in the folder projects, you would type:
This command starts mailx in the file or folder that you have designated. Only headers for the messages in the file or folder are displayed. Select a message to read by typing its number at the mailx prompt, and then press Return. You can also work on mail folders within the mailx program. To see a list of your folders, type this command at a mailx prompt:
To switch from your mailbox to a folder, use the command form:
To return to your mailbox, type this command at a mailx prompt:
To return to the previous folder, type:
Using vi With mailxYou can use the vi text editor to compose messages while you run mailx. vi enables you to correct mistakes and add and delete text before you send your messages. If you are not already familiar with using vi, refer to Chapter 6, Using the vi Editor for instructions. In the mailx program, you can use the standard vi commands for inserting, deleting, and changing text. To write a message with vi:
Mail AliasesA mail alias is a selection of user names that are grouped under a single name. Use mail aliases when you want to send messages to the same group of people over and over. For example, if you occassionally send mail to hank@fretful, george@lonesome, and sally@dakota, you could create a mail alias called amigos. Then, each time you sent mail to amigos, all three people would receive it. Two locations where you can set up mail aliases are:
Mail aliases that are set up in .mailrc behave differently from mail aliases set up in /etc/aliases. These differences are summarized in Table 7-1 at the end of this section. Setting Up Mail Aliases in .mailrcNote the following about setting up mail aliases in .mailrc:
.mailrc is located in your home directory. This file contains several settings that control the behavior of mailx and Mail Tool. To add a mail alias to .mailrc, type:
Note – You can use any text editor to edit the .mailrc file. The previous example shows the method for using the vi editor to edit the file. If you are not already familiar with vi, refer to Chapter 6, Using the vi Editor for instructions. Each mail alias is contained on one line of the file. That is, the line can visually “wrap around” to another line, but it cannot contain carriage returns. Each mail alias should contain the following, separated by spaces:
The following example shows two mail aliases. The first alias (amigos) contains three people. The second alias (softball) contains eight. Notice in softball how the names are visually wrapped around on the screen. This is fine, as long as no carriage returns are used.
To send mail to people on a .mailrc alias, address the mail to the mail alias name. Do not include your machine name. Suppose that you sent the following message:
The recipients would see the following (note the expanded To: line):
Setting Up Mail Aliases in /etc/aliasesNote the following about setting up mail aliases in /etc/aliases:
The format of mail aliases that are created in /etc/aliases is somewhat different from those in .mailrc. Each /etc/aliases alias should use the following format:
To modify your /etc/aliases file, you must first become root. If root is password protected, you'll need to know the root password. Type the following to become the root user on the system:
Notice that the command prompt changes when you become root. The following example shows how the alias softball@texas is added to the default /etc/aliases file.
You can use any text editor to edit the /etc/aliases file. The previous example shows the method for using the vi editor to edit the file. If you are not already familiar with vi, refer to Chapter 6, Using the vi Editor for instructions. Note that the pound signs (#) you see within the /etc/aliases file have been placed there to comment out the text and sample aliases. The pound signs prevent the system from processing this information as actual aliases. Do not place pound signs in front of aliases you add to this file, unless you intentionally want to disable an alias. To send mail to people on a /etc/aliases alias, address the mail by using the name of the alias and your machine name. Suppose that you sent the following:
The recipients would see the following:
Notice that the To: line is not expanded. Whenever you send mail by using a mail alias of this type, be sure to include the machine name of the machine on which it's located. If you set up a mail alias called riders on the machine freeway, then you should send your mail to riders@freeway. Table 7-1 provides a summary comparison between mail aliases that are created in .mailrc and those that are created in /etc/aliases. Table 7–1 Comparing Mail Aliases in .mailrc and /etc/aliases
For more detailed information on mail aliases, type man aliases or man addresses at the system prompt. Tilde CommandsIn the course of composing a message, you can use tilde commands to perform a variety of functions. Tilde commands usually consist of the tilde character (~) followed by a single character. The following table describes some of the more useful tilde characters. Some of these characters have already been introduced in this chapter. Note – If you want to include a literal tilde character in a message, type two tildes in succession. Only one tilde is displayed. Table 7–2 Tilde Commands (mailx)
Getting Help: Other mailx Commandsmailx has two help commands that display lists of commands and functions. When in command mode, you can type ? at the mailx prompt (&) to see a list of commands used in that mode. Similarly, when in input mode (for example, when writing a message), you can use the equivalent command, ~? to view a list of tilde commands (also called “tilde escapes”). The man pages contain extensive information on mailx in more technical form. To see this entry, type the command:
For more information, refer to the man Pages(1): User Commands. |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||