MAIL(1) — USER COMMANDS
NAME
mail, Mail − interactive message-processing system
SYNOPSIS
Mail [ −d ] [ −e ] [ −f [ filename | +folder ] ] [ −H ] [ −i ] [ −n ] [ −N ] [ −T file ] [ −u user ] [ −U ] [ −v ]
Mail [ −d ] [ −F ] [ −h number ] [ −i ] [ −n ] [ −r address ] [ −s subject ] [ −U ] [ −v ] recipient ...
/usr/ucb/mail ...
DESCRIPTION
mail provides a comfortable, flexible environment for sending and receiving electronic messages. While reading mail, mail provides commands to browse, display, save, delete, and respond to messages. While sending mail, mail allows editing and reviewing of a message being composed, and the inclusion of text from files or other messages.
Incoming mail is stored in a standard file for each user, called the system mailbox for that user. When mail is called to read messages, the system mailbox is the default place to find them. As messages are read, they are marked to be moved to a secondary file for storage (unless specific action is taken), so that the messages need not be seen again. This secondary file, called the mbox, is normally the file .mbox in the user’s home directory, but can be changed by setting the MBOX variable. Messages remain in this file until forcibly removed.
OPTIONS
If no recipient is specified, mail attempts to read messages from the system mailbox.
−d Turn on debugging output. (Neither particularly interesting nor recommended.)
−e Test for presence of mail. If there is no mail, mail prints nothing and exits (with a successful return code).
−f [ filename ] Read messages from filename instead of system mailbox. If no filename is specified, the mbox is used.
−f [ + folder ] Use the file folder in the folder directory (same as the folder command). The name of this directory is listed in the folder variable.
−F Record the message in a file named after the first recipient. Overrides the record variable, if set.
−h number The number of network ‘hops’ made so far. This is provided for network software to avoid infinite delivery loops.
−H Print header summary only.
−i Ignore interrupts (as with the ignore variable).
−n Do not initialize from the system default Mail.rc file.
−N Do not print initial header summary.
−r address Pass address to network delivery software. All tilde commands are disabled.
−s subject Set the Subject header field to subject.
−T file Print the contents of the article-id fields of all messages that were read or deleted on file (for the use of network news programs if available).
−u user Read user’s system mailbox. This is only effective if user’s system mailbox is not read protected.
−U Convert uucp style addresses to Internet standards. Overrides the conv environment variable.
−v Pass the −v flag to sendmail(8).
USAGE
Refer to Mail and Messages: Beginner’s Guide for tutorial information about mail.
Starting Mail
As it starts, mail reads commands from a system-wide file (/usr/lib/Mail.rc) to initialize certain variables, then it reads from from a private start-up file called the .mailrc file (it is normally the file .mailrc in your home directory, but can be changed by setting the MAILRC environment variable) for your personal commands and variable settings. Most mail commands are legal inside start-up files. The most common uses for this file are to set up initial display options and alias lists. The following commands are not legal in the start-up file: !, Copy, edit, followup, Followup, hold, mail, preserve, reply, Reply, replyall, replysender, shell, and visual. Any errors in the start-up file cause the remaining lines in that file to be ignored.
You can use the mail command to send a message directly by including names of recipients as arguments on the command line. When no recipients appear on the mail command line, it enters command mode, from which you can read messages sent to you. If you list no recipients and have no messages, mail prints the message: “No mail for username” and exits.
When in command mode (while reading messages), you can send messages using the mail command.
Sending Mail
While you are composing a message to send, mail is in input mode. If no subject is specified as an argument to the command a prompt for the subject is printed. After entering the subject line, mail enters input mode to accept the text of your message to send.
As you type in the message, mail stores it in a temporary file. To review or modify the message, enter the appropriate tilde escapes, listed below, at the beginning of an input line.
To indicate that the message is ready to send, type a dot (or end-of-file character, normally ^D) on a line by itself. mail submits the message to sendmail(8) for routing to each recipient.
Recipients can be local usernames, Internet addresses of the form:
name@domain
uucp(1C) addresses of the form:
... [ host! ] host! username
filenames, folders or alias groups. If the name of the recipient begins with a pipe symbol (|), the remainder of the name is taken as a shell command to pipe the message through. This provides an automatic interface with any program that reads the standard input, such as lpr(1) to record outgoing mail on paper. An alias group is the name of a list of recipients that is set by the alias command, taken from the host’s /usr/lib/aliases file, or taken from the Yellow Pages aliases domain. See addresses(5) for more information about mail addresses and aliases.
Tilde Escapes
The following tilde escape commands can be used when composing messages to send. Each must appear at the beginning of an input line. The escape character (∼), can be changed by setting a new value for the escape variable. The escape character can be entered as text by typing it twice.
∼! [shell-command]
Escape to the shell. If present, run shell-command.
∼. Simulate end of file (terminate message input).
∼: mail-command
∼_ mail-command
Perform the indicated mail command. Valid only when sending a message while reading mail.
∼? Print a summary of tilde escapes.
∼A Insert the autograph string Sign into the message.
∼a Insert the autograph string sign into the message.
∼b name ... Add the names to the blind carbon copy (Bcc) list. This is like the carbon copy (Cc) list, except that the names in the Bcc list are not shown in the header of the mail message.
∼c name ... Add the names to the carbon copy (Cc) list.
∼d Read in the dead.letter file. The name of this file is listed in the variable DEAD.
∼e Invoke the editor to edit the message. The name of the editor is listed in the EDITOR variable. The default editor is ex(1).
∼f [message-list]
Forward the listed messages, or the current message being read. Valid only when sending a message while reading mail; the messages are inserted without alteration (as opposed to the ∼m escape).
∼h Prompt for the message header lines: Subject, To, Cc, and Bcc. If the header line contains text, you can edit the text by backspacing over it and retyping.
∼i variable Insert the value of the named variable into the message.
∼m [message-list]
Insert text from the specified messages, or the current message, into the letter. Valid only when sending a message while reading mail; the inserted text is shifted to the right by one tab stop.
∼p Print the message being entered.
∼q Quit from input mode by simulating an interrupt. If the body of the message is not empty, the partial message is saved in the dead.letter file.
∼r filename
∼< filename
∼<! shell-command Read in text from the specified file or the standard output of the specified shell-command.
∼s subject Set the subject line to subject.
∼t name ... Add each name to the list of recipients.
∼v Invoke a visual editor to edit the message. The name of the editor is listed in the VISUAL variable. The default visual editor is vi(1).
∼w filename Write the message text onto the given file, without the header.
∼x Exit as with ∼q but don’t save the message in the dead.letter file.
∼| shell-command Pipe the body of the message through the given shell-command. If shell-command returns a successful exit status, the output of the command replaces the message.
Reading Mail
When you enter command mode in order to read your messages, mail displays a header summary of the first several messages, followed by a prompt for one of the commands listed below. The default prompt is the ampersand character (&).
Message are listed and referred to by number. There is, at any time, a current message, which is marked by a ‘>’ in the header summary. For commands that take an optional list of messages, if you omit a message number as an argument, the command applies to the current message.
A message-list is a list of message specifications, separated by spaces, which may include:
. The current message.
n Message number n.
^ The first undeleted message.
$ The last message.
+ The next undeleted message.
− The previous undeleted message.
∗ All messages.
n−m An inclusive range of message numbers.
user All messages from user.
/string
All messages with string in the subject line (case ignored).
:c All messages of type c, where c is one of:
d deleted messages
n new messages
o old messages
r read messages
u unread messages
Note that the context of the command determines whether this type of message specification makes sense.
Additional arguments are treated as strings whose usage depends on the command involved. Filenames, where expected, are expanded using the normal shell filename-substitution mechanism.
Special characters, recognized by certain commands, are documented with those commands.
Commands
While in command mode, if you type in an empty command line (a carriage-return or NEWLINE only), the print command is assumed. The following is a complete list of mail commands:
! shell-command Escape to the shell. The name of the shell to use is listed in the SHELL variable.
# comment Null command (comment). This may be useful in .mailrc files.
= Print the current message number.
? Prints a summary of commands.
alias [alias recipient...]
group [alias recipient...]
Declare an alias for the given list of recipients. The list will be substituted when the alias is used as a recipient while sending mail. When put in the .mailrc file, this command provides you with a record of the alias. With no arguments, the command displays the list of defined aliases.
alternates name... Declares a list of alternate names for your login. When responding to a message, these names are removed from the list of recipients for the response. With no arguments, alternates prints the current list of alternate names.
cd[ directory]
chdir [directory] Change directory. If directory is not specified, $HOME is used.
copy [message-list] [filename]
Copy messages to the file without marking the messages as saved. Otherwise equivalent to the save command.
Copy [message-list] Save the specified messages in a file whose name is derived from the author of the message to be saved, without marking the messages as saved. Otherwise equivalent to the Save command.
delete [message-list] Delete messages from the system mailbox. If the variable autoprint is set, print the message following the last message deleted.
discard [header-field...]
ignore [header-field...]
Suppress printing of the specified header fields when displaying messages on the screen, such as “Status” and “Received”. The fields are included when the message is saved unless the variable alwaysignore is set. The Print and Type commands display all header fields, ignored or not.
dp [message-list]
dt [message-list] Delete the specified messages from the system mailbox, and print the message after the last one deleted. Equivalent to a delete command followed by a print command.
echo [string...] Echo the given strings (like echo(1V)).
edit [message-list] Edit the given messages. The messages are placed in a temporary file and the EDITOR variable is used to get the name of the editor. The default editor is ex(1).
exit
xit Exit from mail without changing the system mailbox. No messages are saved in the mbox (see also quit).
file [filename]
folder [filename] Quit from the current mailbox file and read in the named mailbox file. Several special characters are recognized when used as file names:
% Your system mailbox.
%user The system mailbox for user.
# The previous mail file.
& Your mbox file (of messages previously read).
+filename The named file in the folder directory (listed in the folder variable).
With no arguments, file prints the name of the current mail file, and the number of messages and characters it contains.
folders Print the name of each mail file in the folder directory (listed in the folder variable).
followup [message] Respond to a message, recording the response in a file, name of which is derived from the author of the message (overrides the record variable, if set). See also the Followup, Save, and Copy commands and the outfolder variable.
Followup [message-list]
Respond to the first message in the message list, sending the message to the author of each message in the list. The subject line is taken from the first message, and the response is recorded in a file, the name of which is derived from the author of the first message (overrides the record variable, if set). See also the followup, Save, and Copy commands and the outfolder variable.
from [message-list] Print the header summary for the indicated messages or the current message.
group alias name... Same as the alias command.
headers [message] Prints the page of headers that includes the message specified, or the current message. The screen variable sets the number of headers per page. See also the z command.
help Prints a summary of commands.
hold [message-list]
preserve [message-list]
Holds the specified messages in the system mailbox.
if s|r|t
mail-command
...
else
mail-command
...
endif Conditional execution, where s will execute following mail-command up to an else or endif, if the program is in send mode, r executes the mail-command only in receive mode, and t executes the mail-command only if mail is being run from a terminal. Useful primarily in the .mailrc file.
ignore [header-field...]
Same as the discard command.
list Prints all commands available. No explanation is given.
mail recipient... Mail a message to the specified recipients.
mbox [message-list] Arrange for the given messages to end up in the standard mbox file when mail terminates normally. See also the exit and quit commands.
new [message-list]
New [message-list]
unread [message-list]
Unread [message-list]
Takes a message list and marks each message as not having been read.
next message Go to next message matching message. A message-list can be given instead of message, but only first valid message in the list is used. (This can be used, for instance, to jump to the next message from a specific user.)
pipe [message-list] [shell-command]
| [message-list] [shell-command]
Pipe the message through shell-command. The message is treated marked as read (and normally saved to the mbox file when mail exits). If no arguments are given, the current message is piped through the command specified by the value of the cmd variable. If the page variable is set, a form feed character is inserted after each message.
preserve [message-list]
Same as the hold command.
print [message-list]
type [message-list] Print the specified messages. If the crt variable is set, messages longer than the number of lines it indicates paged through the command specified by the PAGER variable. The default paging command is more(1).
Print [message-list]
Type [message-list] Print the specified messages on the screen, including all header fields. Overrides suppression of fields by the ignore and retain commands.
quit Exit from mail storing messages that were read in the mbox file and unread messages in the system mailbox. Messages that have been explicitly saved in a file are deleted unless the variable keepsave is set.
reply [message-list]
respond [message-list]
replysender [message-list]
Send a response to the author of each message in the message-list. The subject line is taken from the first message. If record is set to a filename, a copy of the the reply is added to that file. If the replyall variable is set, the actions of Reply/Respond and reply/respond are reversed. The replysender command is not affected by the replyall variable, but sends each reply only to the sender of each message.
Reply [message]
Respond [message]
replyall [message] Reply to the specified message, including all other recipients of that message. If the variable record is set to a filename, a copy of the reply added to that file. If the replyall variable is set, the actions of Reply/Respond and reply/respond are reversed. The replyall command is not affected by the replyall variable, but always sends the reply to all recipients of the message.
retain Add the list of header fields named 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. The set of retained fields specified by the retain command overrides any list of ignored fields specified by the ignore command. 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.
save [message-list] [filename]
Save the specified messages in the named file. The file is created if it does not exist. If no filename is specified, the file named in the MBOX variable is used, mbox in your home directory by default. Each saved message is deleted from the system mailbox when mail terminates unless the keepsave variable is set. See also the exit and quit commands.
Save [message-list] Save the specified messages in a file whose name is derived from the author of the first message. The name of the file is taken from the author’s name, with all network addressing stripped off. See also the Copy, followup, and Followup commands and the outfolder variables.
set [variable[ =value]]
Define a variable. To assign a value to variable, separate the variable name from the value by an equal-sign (=) (there must be no space before or after the =). A variable may be given a null, string, or numeric value. To embed spaces within a value enclose it in quotes.
With no arguments, set displays all defined variables and any values they might have. See Variables for a description of all predefined mail variables.
shell Invoke the interactive shell listed in the SHELL variable.
size [message-list] Print the size in characters of the specified messages.
source filename Read commands from the given file and return to command mode.
top [message-list] Print the top few lines of the specified messages. If the toplines variable is set, it is taken as the number of lines to print. The default number is 5.
touch [message-list] Touch the specified messages. If any message in message-list is not specifically saved in a file, it will be placed in the mbox upon normal termination. See also the exit and quit commands.
type [message-list] Same as the print command.
Type [message-list] Same as the Print command.
undelete [message-list]
Restore deleted messages. This command only restores messages deleted in the current mail session. If the autoprint variable is set, the last message restored is printed.
unread [message-list]
Unread [message-list]
Same as the new command.
unset variable... Erases the specified variables. If the variable was imported from the environment (that is, an environment variable or exported shell variable), it cannot be unset from within mail.
version Prints the current version and release date of the mail utility.
visual [message-list] Edit the given messages with the screen editor listed in the VISUAL variable. The default screen editor is vi(1). Each message is placed in a temporary file for editing.
write [message-list] [filename]
Write the given messages onto the specified file, but without the header and trailing blank line. Otherwise, this is equivalent to the save command.
xit Same as the exit command.
z [+|−] Scroll the header display forward (+) or backward (−) one screenfull. The number of headers displayed is set by the screen variable.
Forwarding Messages
To forward a specific message, include it in a message to the desired recipients with the ∼f or ∼m tilde escapes. To forward mail automatically, add the addresses of additional recipients to the .forward file in your home directory. Note that forwarding addresses must be valid, or the messages will "bounce." (You cannot, for instance, reroute your mail to a new host by forwarding it to your new address if it is not yet listed in the YP aliases domain.)
Variables
The behavior of mail is governed by a set of predefined variables that are set and cleared using the set and unset commands. Values for the following variables are read in automatically from the environment; they cannot be altered from within mail:
HOME =directory
The user’s home directory.
MAILRC =filename
The name of the personal start-up file. The default is $HOME/.mailrc.
Below are listed the remaining predefined variables recognized by mail. Each can be initialized within the .mailrc file, or set and altered at any time while in mail, using the set command. They can also be imported from the environment (in which case their values cannot be changed within mail). The unset command clears variables. The set command can also be used to clear a variable by prefixing the word no to the name of the variable to clear.
Variables for which values are normally supplied are indicated with an equal-sign (=). The equal-sign is required by the set command, and there can be no spaces between the variable-name, equal-sign, and value, using set to assign a value.
allnet All network names whose last component (login name) match are treated as identical. This causes the message list specifications to behave similarly. Default is noallnet. See also the alternates command and the metoo variable.
alwaysignore Ignores header fields with ignore everywhere, not just during print or type. Affects the save, Save, copy, Copy, top, pipe, and write commands, and the ~m and ∼f tilde escapes.
append Upon termination, append messages to the end of the mbox file instead of prepending them. Default is noappend but append is set in the global start-up file (which can be suppressed with the −n command line option).
askcc Prompt for the Cc list after message is entered. Default is noaskcc.
asksub Prompt for subject if it is not specified on the command line with the −s option. Enabled by default.
autoprint Enable automatic printing of messages after delete and undelete commands. Default is noautoprint.
bang Enable the special-casing of exclamation points (!) in shell escape command lines as in vi. Default is nobang.
cmd=shell-command
Set the default command for the pipe command. No default value.
conv=conversion
Convert uucp addresses to the specified address style. The only valid conversion now is internet, which requires a mail delivery program conforming to the RFC822 standard for electronic mail addressing. Conversion is disabled by default. See also sendmail and the −U command line option.
crt=number Pipe messages having more than number lines through the command specified by the value of the PAGER variable (more by default). Disabled by default.
DEAD =filename
The name of the file in which to save partial letters in case of untimely interrupt or delivery errors. Default is the file dead.letter in your home directory.
debug Enable verbose diagnostics for debugging. Messages are not delivered. Default is nodebug.
dot Take a period on a line by itself during input from a terminal as end-of-file. Default is nodot but dot is set in the global start-up file (which can be suppressed with the −n command line option).
EDITOR =shell-command
The command to run when the edit or ∼e command is used. Default is ex(1).
escape=c Substitute c for the ∼ escape character.
folder=directory
The directory for saving standard mail files. User specified file names beginning with a plus (+) are expanded by preceding the filename with this directory name to obtain the real filename. If directory does not start with a slash (/), the value of HOME is prepended to it. There is no default for the folder variable. See also outfolder below.
header Enable printing of the header summary when entering mail. Enabled by default.
hold Preserve all messages that are read in the system mailbox instead of putting them in the standard mbox save file. Default is nohold.
ignore Ignore interrupts while entering messages. Handy for noisy dial-up lines. Default is noignore.
ignoreeof Ignore end-of-file during message input. Input must be terminated by a period (.) on a line by itself or by the ∼. command. Default is noignoreeof. See also dot above.
keep When the system mailbox is empty, truncate it to zero length instead of removing it. Disabled by default.
keepsave Keep messages that have been saved in other files in the system mailbox instead of deleting them. Default is nokeepsave.
LISTER =shell-command
The command (and options) to use when listing the files in the folder directory. The default is ls(1V).
MBOX =filename
The name of the file to save messages which have been read. The xit command overrides this variable, as does saving the message explicitly to another file. Default is the file mbox in your home directory.
metoo If your login appears as a recipient, do not delete it from the list. Default is nometoo.
no When used as a prefix to a variable name, has the effect of unsetting the variable.
onehop When responding to a message that was originally sent to several recipients, the other recipient addresses are normally forced to be relative to the originating author’s machine for the response. This flag disables alteration of the recipients’ addresses, improving efficiency in a network where all machines can send directly to all other machines (that is, one hop away).
outfolder Locates the files used to record outgoing messages in the directory specified by the folder variable unless the pathname is absolute. Default is nooutfolder. See folder above and the Save, Copy, followup, and Followup commands.
page Used with the pipe command to insert a form feed after each message sent through the pipe. Default is nopage.
PAGER =shell-command
The command to use as a filter for paginating output, along with any options to be used. Default is more(1).
prompt=string
Set the command mode prompt to string Default is &.
quiet Refrain from printing the opening message and version when entering mail Default is noquiet.
record=filename
Record all outgoing mail in filename. Disabled by default. See also the variable outfolder.
replyall Reverses the effect of the reply and Reply commands.
save Enable saving of messages in the dead.letter file on interrupt or delivery error. See DEAD for a description of this file. Enabled by default.
screen=number
Sets the number of lines in a screen−full of headers for the headers command.
sendmail=shell-command
Alternate command for delivering messages. Default is sendmail(8).
sendwait Wait for background mailer to finish before returning. Default is nosendwait.
SHELL =shell-command
The name of a preferred command interpreter. Typically inherited from the environment, the shell is normally the one you always use. Otherwise defaults to sh(1).
showto When displaying the header summary and the message is from you, print the recipient’s name instead of the author’s name.
sign=autograph
The autograph text inserted into the message when the ∼a (autograph) command is given. No default (see also the ∼i tilde escape).
Sign=autograph
The autograph text inserted into the message when the ∼A command is given. No default (see also the ∼i tilde escape).
toplines=number
The number of lines of header to print with the top command. Default is 5.
verbose Invoke sendmail with the −v flag.
VISUAL =shell-command
The name of a preferred screen editor. Default is vi.
FILES
$HOME/.mailrc personal start-up file
$HOME/.forward list of recipients for automatic forwarding of messages
$HOME/mbox secondary storage file
$HOME/dead.letter undeliverable messages file
/usr/spool/mail directory for system mailboxes
/usr/lib/Mail.help∗ help message files
/usr/lib/Mail.rc global start-up file
/tmp/R[emqsx]∗ temporary files
SEE ALSO
binmail(1), mailtool(1) sendmail(8), biff(1), fmt(1), addresses(5), newaliases(8), vacation(1)
mail is found in /usr/ucb/Mail, as a link to /usr/ucb/mail. If you wish to use the original (version 7) UNIX mail program, you can find it in /bin/mail. Its man page is named binmail(1).
BUGS
Where shell-command is shown as valid, arguments are not always allowed. Experimentation is recommended.
Internal variables imported from the execution environment cannot be unset.
Replies do not always generate correct return addresses. Try resending the errant reply with onehop set.
mail does not lock your record file. So, if you use a record file and send two or more messages simultaneously, lines from the messages may be interleaved in the record file.
Sun Release 3.2 — Last change: 17 July 1986