Содержащиеся вНайти другие документыРесурсы поддержки | Загрузить это руководство в формате PDF (546 КБ)
Chapter 7 Using MailSunOS provides a program called mailx for sending and receiving electronic mail (email). mailx provides facilities 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 may prefer to use the window-based mail, you may 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're in the OpenWindows 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 this may 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 will affect your "in tray," thus confusing Mail Tool. 7.1 mailx BasicsIn this section you will learn just enough about mailx to get by. In later sections you will learn about features and functions that will greatly 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've read your mail, mailx automatically places these letters in a storage file called mbox, which is also located in your home directory. 7.1.1 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 will display the message:
where username is your login name. 7.1.2 Sending Yourself a Sample LetterTo see at a glance how mailx works, you can begin by sending yourself a sample letter. 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 may be able to use just your login on a local network--consult your system administrator when in doubt.
The program will respond with a Subject: line:
If you like, type in a word or two here about the content of the letter you're sending yourself and press Return. Now type the body of the letter; use short lines and press Return at the end of each line. (Note that you can only make corrections as you go by backspacing and retyping lines before you press Return.) Your sample letter might look something like this (the spaces between lines are made by pressing Return twice):
To send your sample letter, press Return to complete the last line of the letter and then press Ctrl-D. After your letter has been sent, the system returns a command prompt. 7.1.3 Reading Your Sample LetterTo read your sample letter, give the mailx command again. Your screen will probably 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 letter you sent yourself. The "N" at the beginning of the line means that it's a "new" letter. A "U" (unread) means the letter was new, but was not read before quitting the mailx program previously. (The information in this screen is discussed in greater detail in "7.2 Reading Letters", in this chapter.) Every letter is assigned a number as it is received: Rose's letter to herself is shown as letter number 1. To read a letter, type its number at the mailx prompt, the ampersand (&), as follows:
7.1.4 Quitting mailxWhen you're finished using mailx, you can quit the program using one of two commands: q (quit) or x (exit). If you type q at the mailx prompt and then press Return,
you will then see a message similar to the following: Saved one message in home_directory/mbox. where home_directory is the path name to your home directory. When you use q to quit mailx after reading messages, mailx moves the letters 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 letters you've already read into the mbox file. 7.2 Reading LettersIf 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 letters, type mailx at a command prompt and press Return. If there's no mail waiting for you, you will see the message: No mail for username Otherwise, you will 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 letters received, and their status. Next, mailx shows a numbered list of the letters in your mailbox. From left to right, the columns in each line specify:
When you have a large number of letters in your mailbox, the displayed list may not show all of your mail. If this is the case, type: To view the current letter in the mailbox list (marked with >), press Return. Pressing Return again will display the next letter. To read any letter in the list, type its number and press Return. 7.3 Deleting (and Undeleting) LettersWhen you are finished reading a letter, you may decide you want to delete it rather than have it saved to your mbox file (the default when you quit the mailx program). To delete the last letter you read, just type d at the mailx prompt. To delete a specific letter from your mailbox, use the command form: d number For example, to delete the second letter, give this command from within mailx:
You can also delete several letters at a time. To delete letters 1 and 3, give the command:
To delete a range of letters, for example 1 through 3, give the command:
Before quitting mail, you can undelete letters you've removed from your mailbox. Use the command form: u number followed by Return. For example, to undelete the second letter, give this command:
If you want 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, typing u will undelete messages 2, 3, 4, and 5. Note that all deletions are made permanent when you quit mailx with the q command; that is, deleted letters can no longer be undeleted. You can, however, quit mailx with the x command, leaving your mailbox intact -- as mentioned previously, quitting with x will leave read letters marked with a U, deleted letters undeleted, and so forth. 7.4 Printing LettersYou can print a hard copy of a letter by piping a letter to a printer command. To do this, use the command form: |number lp at a mailx prompt. (The | symbol is called a pipe.) For example, to print a copy of letter 2, type:
and press Return. If a letter number is not specified, mailx pipes the current letter to the printer. For more information on piping, see "2.2.5 Redirecting and Piping Command Output" in Chapter 2, Basic SunOS Commands. 7.5 Sending LettersTo send mail with the mailx program, you need to know the login name(s) of the intended recipient(s) of your letter. 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. Typing the who command lists all the users who are currently logged in to the file server you are on. The displayed list contains user's login names, their terminal types, and the date and time they logged in. For example:
Typing the finger command displays the same type of information as who with a little more detail. The information that appears depends on how your system administrator has set up this command. As an example, you may see something like the following:
The rusers command provides information on the users currently logged in to your local network. Refer to Chapter 9, Using the Network, for instructions regarding the use of the rusers command. When you have determined the necessary user information, complete the following steps to send a letter.
7.5.1 Undeliverable LettersIf you specify an incorrect user address when you send a letter, the system responds with the message user@machine...User unknown and the letter is 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 letter cannot be delivered, the file is also copied to a file in your home directory named dead.letter. 7.5.2 Canceling an Unsent LetterYou can cancel a letter at any time before it is sent by pressing Ctrl-C twice. 7.5.3 Adding Carbon and Blind Carbon CopiesBefore sending a letter, you can specify that "carbon copies" be sent to other than the main addressees. You can also send "blind carbons." (Recipients of your letter 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. There are three methods for sending carbon copies with a letter:
7.5.4 Inserting a Copy of a Letter or FileYou can insert a copy of any letter in your mailbox into the letter you're writing. Likewise, you can insert a copy of any text file. 7.5.4.1 Inserting a LetterThe command form to insert a letter is ~m number where number is the number of the letter to be inserted. For example, to send a letter to another user that includes a copy of letter number 3 from your mailbox list, you would do the following:
7.5.4.2 Inserting a FileYou can also insert a copy of any text file into a letter. Use the command form: ~r filename as you're writing a letter. For example, to insert the file outline in the current letter, type:
7.5.5 Replying to a LetterReply to mail by giving the command r number at a mailx prompt. (If you omit the letter number, mailx replies to the current letter.) For example, to reply to the sender of letter 2, give the command:
mailx automatically addresses your letter and supplies an Re: Subject: line that echoes the original Subject: line. Send your reply like any other letter. R is a variant of the reply command that sends your reply to all recipients of the original letter as well as to its sender. Use this command only when absolutely necessary, to avoid generating "junk mail." Note - You can insert a letter into your reply as shown in the previous section. To insert a copy of the letter to which you are replying, just give the command ~m without a letter number. 7.6 Saving and Retrieving LettersIn addition to sending and receiving letters, you may also want to save and retrieve them for later use. In mailx you can save letters by appending them to regular text files; you can also append letters to special files called folders. Both methods are discussed below. mailx makes a distinction between saving letters and copying them; saving removes a letter from the mailbox and appends it to a file or folder; copying leaves a letter in the mailbox and appends a copy to a file or folder. 7.6.1 Saving and Copying Letters in FilesTo save a letter into a file, the command form at the mailx prompt is: s number filename where number is the number of the letter to be saved and filename is the file where you want to save the letter. For example, to save letter 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 letters at once to the same file. For example, to save letters 3, 5, 6, 7, and 8 to ~/notes/finance, you would type:
If the file you specify does not exist, mailx creates it. If the file does exist, mailx appends the letter 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 letter than has been saved. To leave the letter in your mailbox while appending it to another file, use the copy command, as follows:
7.6.2 Saving and Copying Letters in FoldersYou can dispense with typing full pathnames to files if you save or copy letters to mail folders. Folders are special files that are stored in a folder directory. The advantages to saving or copying letters to folders is that your letters are automatically kept together in the same directory, where they are easily accessible without typing long pathnames. 7.6.2.1 Setting the Folder DirectoryTo use folders, you must first set up a folder directory. This is a two-step process:
Now your folder directory is set to receive letters saved in folders. (The change to the .mailrc file will take effect the next time you start mailx.) 7.6.2.2 Designating FoldersYou use the same commands to save or copy letters 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 (Letters). For example, to save letter 3 to a folder called projects, type:
mailx interprets this command as meaning "save letter 3 into ~/Letters/projects." (If the folder doesn't already exist, mailx will create it.) Copy the letter into a folder by typing:
7.6.2.3 Sending a Letter Directly to a File or FolderYou can send copies of your letters 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. 7.6.3 Reading Letters in Files and FoldersTo read letters saved in a file, use the command form: mailx -f filename Using the example above, you would read the file ~/memos/finance by typing:
You can read letters saved in a folder with a similar command--just use the + instead of a pathname. For example, to read the letters in the folder projects, you would type:
This command starts mailx in the file or folder designated. Only headers for the letters in the file or folder are displayed. Select a letter to read by typing its number at the mailx prompt and pressing Return. You can also work on mail folders within the mailx program. To see a list of your folders, type this at a mailx prompt:
To switch from your mailbox to a folder, use the command form:
To return to your mailbox, type this at a mail prompt:
To return to the previous folder, type:
7.7 Using vi with mailxYou can use the vi text editor to compose letters while running mailx. This gives you the capability of correcting mistakes and adding and deleting text before you send your letters. 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 letter with vi:
7.8 Mail AliasesA mail alias is a selection of user names grouped under a single name. Use mail aliases when you want to send letters to the same group of people over and over. For example, if you wanted to send mail from time to time 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. There are two locations where you can set up mail aliases:
Mail aliases 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. 7.8.1 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 a number of 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 example above 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, it can visually "wrap around" to another line, but it cannot contain carriage returns. Each mail alias should contain the following, separated by spaces:
The example below shows two mail aliases. The first (amigos) contains three people. The second (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, just address it to the mail alias name. Do not include your machine name. For example, if you sent the following:
the recipients would see the following (note the expanded To: line):
7.8.2 Setting Up Mail Aliases in /etc/aliasesNote the following about setting up mail aliases in /etc/aliases:
The format of mail aliases 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 example above 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 using the name of the alias and your machine name. For example, if you sent the following:
the recipients would see the following:
Notice that the To: line is not expanded. Whenever you send mail 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 created in .mailrc and those 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. 7.9 Tilde CommandsIn the course of composing a letter, 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 have already been introduced in this chapter. Note - If you want to include a literal tilde character in a letter, type two tildes in succession. Only one tilde will be displayed. Table 7-2 Tilde Commands (mailx)
7.10 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. Likewise, when in input mode (for example, when writing a letter), you can give 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, give the command:
or refer to the man Pages(1): User Commands. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||