[Up] [Next]
Go up to Top
Go forward to Using MH

Using Electronic Mail

There are various programs available for reading and sending electronic mail. The most popular is "BSD mail". There are others such as /bin/mail, MH, elm, Emacs mail, etc. We will only cover BSD mail and MH in this guide.

Introduction to BSD mail

This is an abbreviated introduction to mail. For the whole story type

% man mail
The mail program is composed of sending mail and receiving mail. To read any mail sent to you type
% mail
and you will enter the mail program which has its own prompt, the ampersand (&). All of the commands you can use to read, reply, and dispose of your mail are described in the section titled "Reading mail". To send mail to other people, give mail an argument. To send   a message to one or more other people, mail can be invoked with arguments which are the names of people to send to. You are then expected to type in your message, followed by an EOT (control-D) on a line by itself. For example,
% mail cyndy@foo claire@bar
There should not be any spaces in the mail address, i.e., "cyndy@foo" not "cyndy @ foo". The section below, labeled "Sending mail", describes some features of mail available to help you compose your letter.

Mail has a number of options which can be set in the .mailrc  file to alter its behavior; thus "set askcc" enables the "askcc" feature which automatically prompts you to send a carbon copy. Setting Options describes these commands.

Reading mail

In normal usage mail is given no arguments and checks your mail out of the post office (located in /usr/spool/mail/username), then prints out a one line header of each message there. You will have the mail prompt (the "&") at the left of the screen. The current message is initially the first message (numbered 1) and can be displayed by hitting RETURN or typing the message number.

Disposing of mail

After examining a message you can delete (d) the message. Deletion causes the mail program to forget about the message. This is not irreversible; the message can be undeleted (u) by giving its number, or the mail session can be aborted by giving the exit (x) command which exits the current mail-reading session and leaves all messages "as they were" in /usr/spool/mail/username when you typed mail. Deleted messages will, however, usually disappear never to be seen again.

Replying to mail

To answer a mail message type (R) or (r) after the mail prompt. WARNING: On DEC and HP systems, uppercase R replies only to the sender of the mail while lowercase r replies to all people the mail was sent to so use it judiciously. On Sun systems, lowercase r replies only to the sender of the mail while uppercase R replies to all people the mail was sent. Typing "R" or "r" will automatically repeat the To and Subject field (which can be altered with the use of a ~h command -- see "Sending mail"). Text you then type in, up to an end-of-file (control-d), defines the contents of the message. Replying to mail messages uses the same commands as sending mail so all the commands listed in the section "Sending mail" apply to replying to mail.

Specifying messages

Commands such as print and delete can be given a list of message numbers as arguments to apply to a number of messages at once. Thus "delete 1 2" deletes messages 1 and 2, while "delete 1-5" deletes messages 1 through 5. The special name "*" addresses all messages, and "$" addresses the last message; thus the command top which prints the first few lines of a message could be used in "top *" to print the first few lines of all messages.

Ending a mail processing session

You can end a mail session with the quit (q) command. Messages which have been read get appended to your mbox   file unless they have been deleted in which case they are discarded. Unread messages go back to the post office (/usr/spool/mail/user). The "mbox" file can become quite large if you routinely read messages but do not discard them. Typing
% mail -f
causes the mail program to read in the contents of your mbox for processing just as if it were a current mail-editing session; when you quit , the mail program writes undeleted messages back to this mbox file.

Reading mail

When you type

% mail
to enter the mail program there are commands to use to manipulate and dispose of your mail messages. Each command is typed on a line by itself, and may take arguments following the command word. The command need not be typed in its entirety -- the first command which matches the typed prefix is used. For commands which take message lists as arguments, if no message list is given, then the next message forward which satisfies the command's requirements is used. If there are no messages forward of the current message, the search proceeds backwards, and if there are no good messages at all, mail types "No applicable messages" and aborts the command.
 
+
Goes to the next message and prints it out.
-
Goes to the previous message and prints it out. If given a numeric argument n, goes to the n-th previous message and prints it.
?
Prints a brief summary of mail commands.
!
Executes the UNIX shell command which follows.
Print (P)
Like print but also prints out ignored header fields. See also print and ignore.
alias (a)
With no arguments, prints out all currently-defined aliases. With one argument, prints out that alias. With more than one argument, creates a new or changes an on old alias.
chdir (c)
Changes the user's working directory to that specified, if given. If no directory is given, then changes to the user's login directory.
copy (co)
The copy command does the same thing that save does, except that it does not mark the messages it is used on for deletion when you quit.
delete (d)
Takes a list of messages as argument and marks them all as deleted. Deleted messages will not be saved in mbox , nor will they be available for most other commands.
dp (also dt)
Deletes the current message and prints the next message. If there is no next message, mail says "at EOF."
exit (ex or x)
Effects an immediate return to the Shell without modifying the user's system mailbox or the user's mbox file.
from (f)
Takes a list of messages and prints their message headers.
headers (h)
Lists the current range of headers, which is an 18 message group. If a "+" argument is given, then the next 18 message group is printed, and if a "-" argument is given, the previous 18 message group is printed.
help
A synonym for ?
hold (ho)
(also preserve) Takes a message list and marks each message therein to be saved in the user's system mailbox instead of in mbox . Does not override the delete command.
mail (m)
Takes as argument login names and distribution group names and sends mail to those people; basically, this is sending mail while in the mail program.
mbox
Indicate that a list of messages you have read be sent to mbox in your home directory when you quit. This is the default action for messages if you do not have the hold option set. This option would be set in your .mailrc file as "set hold=/usr/spool/mail/user" where "user" is your login name; or "set hold=filename".
next (n)
(like + or Carriage-Return) Goes to the next message in sequence and types it. With an argument list, types the next matching message.
preserve (pre)
A synonym for hold .
print (p)
Takes a message list and types out each message on the user's terminal.
quit (q)
Terminates the session, saving all undeleted, unsaved messages in the user's mbox file in his login directory, preserving all messages marked with hold or preserve or never referenced in his system mailbox, and removing all other messages from his system mailbox. If new mail has arrived during the session, the message "You have new mail" is given.
reply (r or R)
Takes a message list and sends mail to the sender and all recipients of the specified message, or just to the sender. (see Replying to mail.) The default message must not be deleted.
respond
A synonym for reply .
retain
Add the list of header fields named (i.e., To From Date Subject, etc.) to the retained list. Only the header fields in the retain list are shown on your terminal when you print a message. All other header fields are suppressed. This gets rid of all the extraneous information about machine hops the mail message took to get to you. The Type and Print commands can be used to print a message in its entirety. If retain is executed with no arguments, it, lists the current set of retained fields. This is a useful option to set in your .mailrc file.
save (s)
Takes a message list and a filename and appends each message in turn to the end of the file. The filename in quotes, followed by the line count and character count is echoed on the user's terminal. save saves the file in the directory you called mail from; you can save a file in another director level by giving a full pathname.
set (se)
With no arguments, prints all variable values set in your .mailrc file. Otherwise, sets the option given in the argument. Arguments are of the form "set option=value" (no space before or after the equals sign =) or "set option".
top
Takes a message list and prints the top few lines of each. The number of lines printed is controlled by the variable toplines (which you can set in your .mailrc file) and defaults to five.
type (t)
A synonym for print .
unalias
Takes a list of names defined by alias commands and discards the remembered groups of users. The group names no longer have any significance.
undelete (u)
Takes a message list and marks each one as not being deleted.
write (w)
A synonym for save .
z (z-)
Will read the next screenfull (or back a screenfull) messages. Mail will only print the first 22--23 messages, even if there are over that amount in your current mail. Typing z will go to the next 24. Typing z- will go back 24.

Sending mail

While you are composing a message, mail treats lines beginning with the character `~' specially. For instance, typing "~h" (alone on a line) will repeat the message headers (To, Subject, cc). Other escapes will set up subject fields, add and delete recipients to the message and allow you to escape to an editor to revise the message or to a shell to run some commands. Tilde escapes are only recognized at the beginning of lines. Some of these "~" commands are more useful when applied to sending mail during a read mail session (such as ~m and ~f). Here is a summary of the tilde escapes, which are used when composing messages to perform special functions:  

~b name
Add the given names to the list of carbon copy recipients but do not make the names visible in the Cc: line ("blind carbon copy").
~c name
Add the given names to the list of carbon copy recipients.
~e
Invoke the text editor (ex) on the message collected so far. After the editing session is finished and you ":wq", you may continue appending text to the message. If $EDITOR is set to another editor, then it will be used instead of ex. Also, see Changing the Default Editor.
~f messages
Read the named messages into the message being sent. If no messages are specified, read in the current message.
~h
Edit the message header fields by typing each one in turn and allowing the user to append text to the end or modify the field by using the current terminal erase and kill characters.
~m messages
Read the named messages into the message being sent, shifted right one tab. If no messages are specified, read the current message.
~p
Print out the message collected so far, prefaced by the message header fields.
~q
Abort the message being sent, copying the message to "dead.letter" in your home directory if save is set. If do not wish to have a copy of aborted letters saved then do "set nosave" in your .mailrc file. The ~q command is synonmous to typing control-C twice.
~r filename
Read the named file into the message.
~t name
Add the given names to the direct recipient list.
~v
Invoke the visual editor on the message collected so far. By default, this is vi. If $VISUAL is set to another editor, then it will be used instead. After you quit the editor, you may resume appending text to the end of your message.
~w filename
Write the message onto the named file.
~dot
causes the mail program to interpret a period alone on a line as the terminator of a message you are sending (replaces control-d).

Setting Options in mail

Options are controlled via the set and unset commands. Options may be set or not set, or set to a value. You can set them in your .mailrc file by doing:

set option
or
set option=value
As an example: "set ask" sets up the Subject: prompt when sending mail (this is often set up for you by the system manager for all new accounts). Here is a list of options:
append
Causes messages saved in mbox to be appended to the end rather than prepended.
ask
Causes mail to prompt you for the subject of each message you send. If you respond with simply a newline, no subject field will be sent.
askcc
Causes you to be prompted for additional carbon copy recipients at the end of each message. Responding with a newline indicates your satisfaction with the current list.
autoprint
Causes the delete command to behave like dp -- thus, after deleting a message, the next one will be typed automatically.
escape
if defined, the first character of this option gives the character to use in the place of "~" to denote escapes.
hold
This option is used to hold messages in the system mailbox by default.
metoo
Usually, when a group alias is expanded that contains the sender, the sender is removed from the expansion. Setting this option causes the sender to be included in the group.
nosave
Normally, when you abort a message with two interrupt characters (control-c's), mail copies the partial letter to the file "dead.letter" in your home directory. Setting the option nosave prevents this.
crt
The valued option crt is used as a threshold to determine how long a message must be before more is used to read it, i.e., keep long messages from quickly scrolling by on the screen. The usual setting is "set crt=24".
record
If defined, gives the pathname of the file used to record all outgoing mail. If not defined, then outgoing mail is not so saved. Use is "set record=mailsent" (or any file name you wish).
toplines
If defined, gives the number of lines of a message to be printed out with the top command; normally, the first five lines are printed.

Using mail aliases

You can take advantage of the "alias" command in to define a single name to expand to a list of names. For a personal alias define it in your .mailrc file:

alias cohorts bill jenny@ucb lee michelle
Now when you type "mail cohorts" the mail list will be expanded to send mail to the everyone in the list. In mail you send, personal aliases will be expanded in mail sent to others so that they will be able to reply to the recipients. You can examine all of your aliases while you are reading mail by typing "alias" after the mail prompt.

There is also a system-wide alias list. To read it type:

% more /usr/lib/aliases

sharon@eecs.berkeley.edu
janp@eecs.berkeley.edu
April 11, 1995

[Up] [Next]