MAIL(1) NetBSD General Commands Manual MAIL(1)
NAMEmail, mailx, Mail -- send and receive mail
SYNOPSISmail [-EIinv] [-afile] [-bbcc-addr] [-ccc-addr] [-rrcfile]
[-ssubject] to-addr ... [- sendmail-flags]
mail [-EIiNnv] [-H[colon-modifier]] -f [name]
mail [-EIiNnv] [-H[colon-modifier]] [-uuser]
DESCRIPTIONmail is an intelligent mail processing system, which has a command syntax
reminiscent of ed(1) with lines replaced by messages.
-a Attach file to the message.
-b Send blind carbon copies to list. List should be a comma-separated
list of names.
-c Send carbon copies to list of users.
-E Don't send messages with an empty body. This is useful for piping
errors from cron scripts.
-f Read in the contents of your mbox (or the specified file) for pro-
cessing; when you quit, mail writes undeleted messages back to this
file.
-H Print the header summaries and exit. The optional colon-modifier
string must begin with a `:' and be followed by one or more of the
characters described in the Specifying messages section below.
E.g., ``mail -H:n'' will display just new message headers.
-I Forces mail to run in interactive mode even when input isn't a ter-
minal. In particular, the ~ special character when sending mail is
only active in interactive mode.
-i Ignore tty interrupt signals. This is particularly useful when
using mail on noisy phone lines.
-N Inhibits the initial display of message headers when reading mail
or editing a mail folder.
-n Inhibits reading /etc/mail.rc upon startup.
-r Specify an alternate user rcfile to load. This overrides the value
specified in the environment variable MAILRC which in turn over-
rides the default ~/.mailrc file.
-s Specify subject on command line (only the first argument after the
-s flag is used as a subject; be careful to quote subjects contain-
ing spaces.)
-u Is equivalent to:
mail -f /var/mail/user
-v Verbose mode. The details of delivery are displayed on the user's
terminal.
Sending mail
To send a message to one or more people, mail can be invoked with argu-
ments which are the names of people to whom the mail will be sent. You
are then expected to type in your message, followed by a `control-D' at
the beginning of a line.
Any flags following the list of recipients, will be passed, together with
their arguments, directly to sendmail(1). For example to change your
From address to somebody@somewhere.net you can specify:
mail recipient -f somebody@somewhere.net
To prevent multiple copies of a message being sent to the same address,
duplicate addresses (after alias expansion) are removed from the
bcc-addr, cc-addr, and to-addr lists. In addition, addresses on the
cc-addr and to-addr lists are removed if they occur on the bcc-addr list
and addresses on the cc-addr list are removed if they occur on the
to-addr list. If the to-addr list is empty after these deletions, most
systems will insert the line ``To: undisclosed recipients:;''.
The section below Replying to or originating mail, describes some fea-
tures of mail available to help you compose your letter.
Reading mail
In normal usage mail is given no arguments and checks your mail out of
the post office, then prints out a one line header of each message found.
The current message is initially the first message (numbered 1) and can
be printed using the print command (which can be abbreviated p). You can
move among the messages much as you move between lines in ed(1), with the
commands + and - moving backwards and forwards, and simple numbers.
Disposing of mail
After examining a message you can delete (d) the message or reply (r) to
it. Deletion causes the mail program to forget about the message. This
is not irreversible; the message can be undeleted (u) by giving its num-
ber, or the mail session can be aborted by giving the exit (x) command.
Deleted messages will, however, usually disappear never to be seen again.
Specifying messages
Many commands (e.g., delete, from, and print) accept a list of messages
as an argument. Messages may be specified by their message number, by a
range of messages, or by a pattern string matching certain fields in the
header as described below. These message ``specs'' may be combined by
the usual binary boolean operations `&', `|', and `^', which denote,
respectively, a logical ``and'', ``or'', and ``xor''. Logical expres-
sions may be grouped with parentheses `(' and `)' and negated with `!'.
If the binary operator is missing between two message specs, it is
assumed to be a `|'. This is for simplicity, backwards compatibility,
and also to to facilitate using the `|' symbol to denote a pipe. (See
enable-pipes.)
Besides the obvious (base10) message numbers, the characters `^', `-',
`.', `+', and `$' denote, respectively, the first message, the message
before the ``dot'' (the current message), the ``dot'' message, the mes-
sage following the ``dot'', and the last message.
A ``message range'' consists of two message numbers separated by a `-'.
A `*' denotes all messages and is equivalent to `^-$'.
A pattern is a string (not beginning with any of the above special char-
acters). If it does not begin with a `/', it is compared with the
senders address. If it begins with a `/', and searchheaders is not
defined, the remainder of the string is compared with the subject field.
(See searchheaders for searching other header fields or the message
body.) If regex-search is not defined, then the comparison is a simple
case insensitive substring match. (See regex-search for regular expres-
sion matches.)
A list of messages may be restricted by a ``colon-modifier'' string,
i.e., a `:' followed by one or more of the characters:
d deleted
e edited
m mboxed
n new
o old
p preserved
r read
s saved
t tagged
u unread and not new
! invert the meaning of the colon-modifiers
If there are no address specifications other than colon-modifiers, the
colon-modifiers apply to all messages. Thus ``from netbsd :n'' would
display the headers of all new messages with `netbsd' in the sender's
address, while ``from :!r'' and ``from :nu'' would both display all new
and unread messages. Multiple colon-modifiers may be specified and a
single `:' with no letters following indicates the colon-modifier from
the preceding command.
For example:
from 1 12 3-5
would display the headers from messages 1, 3, 4, 5, and 12.
from anon & ( /foo | /bar )
would display all headers that had `anon' in the sender's address and
either `foo' or `bar' in the subject line.
Generally, commands cannot select messages that are not displayed, such
as deleted or hidden messages, the exception being the undelete command.
Replying to or originating mail
You can use the reply command to set up a response to a message, sending
it back to the person who it was from. Text you then type in, up to an
end-of-file, defines the contents of the message. While you are compos-
ing a message, mail treats lines beginning with the character ~ spe-
cially. For instance, typing ~m (alone on a line) will place a copy of
the current message into the response right shifting it by a tab stop
(see indentprefix variable, below). 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.
(These options are given in the summary below.)
Ending a mail processing session
You can end a mail session with the quit (q) command. Messages which
have been examined go to your mbox file unless they have been deleted in
which case they are discarded. Unexamined messages go back to the post
office. (See the -f option above).
Personal and system wide distribution lists
It is also possible to create a personal distribution lists so that, for
instance, you can send mail to ``cohorts'' and have it go to a group of
people. Such lists can be defined by placing a line like
alias cohorts bill ozalp jkf mark kridle@ucbcory
in the file .mailrc in your home directory. The current list of such
aliases can be displayed with the alias command in mail. System wide
distribution lists can be created by editing /etc/mail/aliases, see
aliases(5) and sendmail(1); these are kept in a different syntax. 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. System wide
aliases are not expanded when the mail is sent, but any reply returned to
the machine will have the system wide alias expanded as all mail goes
through sendmail(1).
Network mail (ARPA, UUCP, Berknet)
See mailaddr(7) for a description of network addresses.
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. (These
options are summarized below.)
SUMMARY
(Adapted from the ``Mail Reference Manual'')
Each command is typed on a line by itself, and may take arguments follow-
ing 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.
! Executes the shell (see sh(1) and csh(1)) command which follows.
- Print out the preceding message. If given a numeric argument n,
goes to the n'th previous message and prints it.
= With no argument, it displays the current message number. Other-
wise, set the current message number to its first argument.
? Prints a brief summary of commands.
| Pipe the current message body through the shell (see sh(1) and
csh(1)) command which follows.
Detach Like detach but also saves MIME parts that don't have a filename
associated with them. For the unnamed parts, a filename is sug-
gested containing the message and part numbers, and the subtype.
Header (H) Specify or show additional header fields. This is intended
for adding extra header fields like ``Reply-To:'' or
``X-Organization:'' to the header. For example:
Header X-Mailer: NetBSD mail(1) 9.1
would add the ``X-Mailer: NetBSD mail(1) 9.1'' line to the mes-
sage header. Without any arguments, the extra header fields are
displayed. With only a header name (including the `:'), it will
delete all extra header fields with that name. Note: Although
some syntax checking is done on the header line, care should be
taken to ensure that it complies with RFC 2821 and 2822. Also,
the extra header lines are not currently displayed by the ~h
tilde command when sending mail (use ~:Header to see them).
More (M) Like more but also prints out ignored header fields.
Page (Pa) A synonym for More.
Print (P) Like print but also prints out ignored header fields. See
also print, more, page, type, view, ignore, and retain.
Reply (R) Reply to originator. Does not reply to other recipients of
the original message. (See reply.)
Save (S) Same as save except that all header fields are saved ignoring
the saveignore or saveretain lists.
Type (T) Identical to the Print command.
View (V) Like Print but has the opposite MIME decoding behavior. (See
the mime-decode-message variable.)
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 alias or changes an old one.
alternates
(alt) The alternates command is useful if you have accounts on
several machines. It can be used to inform mail that the listed
addresses are really you. When you reply to messages, mail will
not send a copy of the message to any of the addresses listed on
the alternates list. If the alternates command is given with no
argument, the current set of alternative names is displayed.
bounce Takes a list of messages and prompts for an address to bounce the
messages to. If no message is specified, the current message is
used. All the original header fields are preserved except for
the `Delivered-To', `X-Original-To' and `Status' fields. The new
`To' field contains the bounce address(es) plus any addresses in
the old `To' field minus the user's local address and any on the
alternates list. (See the alternates command.)
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.
deldups
Delete duplicate messages based on their `Message-Id' field,
keeping the first one in the current sort order. This can be
useful with replies to a mailing list that are also CCed to a
subscriber. (The same thing can also be accomplished with the
threading and tagging commands.)
delete (d) Takes a list of messages as an argument and marks them all as
deleted. Deleted messages will not be saved in mbox, nor will
they be available for most other commands.
detach Takes a message list followed by a target directory as arguments,
decodes each MIME part in the message list, and saves it in the
target directory. If the message list is empty, use the current
message. If the directory is not specified, use the directory
specified by mime-detach-dir variable and, if that is empty,
default to the directory mail was started in. For each MIME part
in the message list, the filename is displayed for confirmation
or changes. If an empty name is entered, the part is skipped.
If the filename already exists, the user will be prompted before
overwriting it. (See the mime-detach-batch and
mime-detach-overwrite variables to change this behavior.) Only
MIME parts with an associated filename in the `Content-Type' or
`Content-Disposition' fields are decoded. (See Detach to detach
all parts.) The MIME extension hooks and character set conver-
sion are ignored.
dp (also dt) Deletes the current message and prints the next mes-
sage. If there is no next message, mail says ``at EOF''.
down Go down one level in the thread. If given a message number, it
descends the thread below that message, otherwise it descends
from the current message (dot).
edit (e) Takes a list of messages and points the text editor at each
one in turn. On return from the editor, the message is read back
in.
else Switch the command execution condition set by the previous if,
ifdef, or ifndef command.
endif Terminate an if, ifdef, or ifndef command.
exit (ex or x) Effects an immediate return to the Shell without modi-
fying the user's system mailbox, his mbox file, or his edit file
in -f.
expandaddr
If unset (the default), recipient addresses must be names of
local mailboxes or Internet mail addresses. If set, shell expan-
sion of existing mailbox names will be performed.
expose Expose the thread structure so all messages appear in header
listings. (See hide for the inverse.) The default header prompt
will indent each header line one space for each level in the
threading. The ``%?* ?'' format string does this.
file (fi) The same as folder.
flatten
For each message number in the argument list, or the current
thread if no message list is given, promote all exposed children
to the same thread level.
folders
List the names of the folders in your folder directory.
folder (fo) The folder command switches to a new mail file or folder.
With no arguments, it tells you which file you are currently
reading. If you give it an argument, it will write out changes
(such as deletions) you have made in the current file and read in
the new file. Some special conventions are recognized for the
name. `#' means the previous file, `%' means your system mail-
box, `%user' means user's system mailbox, `&' means your mbox
file, and `+file' means a file in your folder directory.
forward
Takes a list of messages and prompts for an address (or
addresses) to forward each message to. If no message list is
specified, the current message is used. The mail editor is run
for each message allowing the user to enter a message that will
precede the forward message. The message is sent as a multi-
part/mixed MIME encoded message. All header fields except the
`Status' field are included.
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 ?hide Collapse the threads so that only the head of each thread is
shown, hiding the subthreads. (See expose for the inverse.)
hidetags
Restrict the display to untagged messages. In threaded mode,
subthreads that connect directly to an untagged message are also
displayed, including tagged messages in the connecting chain.
hidethreads
The same as hide.
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.
if Execute commands that follow depending on the operating mode.
The current supported modes are `receiving', `sending', and
`headersonly'. For example, one use might be something like:
if headersonly
set header-format="%P%Q%3i %-21.20f %m/%d %R %3K \"%q\""
else
set header-format="%P%Q%?& ?%3i %-21.20f %a %b %e %R %3K/%-5O \"%q\""
endif
ifdef Execute commands that follow if the specified variable is
defined. Note: This includes environment variables.
ifndef Execute commands that follow if the specified variable is not
defined.
ignore Add the list of header fields named to the ignored list. Header
fields in the ignore list are not printed on your terminal when
you print a message. This command is very handy for suppression
of certain machine-generated header fields. The Type and Print
commands can be used to print a message in its entirety, includ-
ing ignored fields. If ignore is executed with no arguments, it
lists the current set of ignored fields.
inc Incorporate any new messages that have arrived while mail is
being read. The new messages are added to the end of the message
list, and the current message is reset to be the first new mail
message. This does not renumber the existing message list, nor
does it cause any changes made so far to be saved.
invtags
Invert the tags on a list of messages or the current message if
none are given. Note: this will not affect any currently deleted
messages.
mail (m) Takes as argument login names and distribution group names
and sends mail to those people.
mbox Indicate that a list of messages 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.
mkread (mk) Takes a message list and marks each message as having been
read.
more (mo) Takes a message list and invokes the pager on that list.
next (n, like + or CR) Goes to the next message in sequence and types
it. With an argument list, types the next matching message.
page (pa) A synonym for more.
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 mes-
sages 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 sys-
tem mailbox. If new mail has arrived during the session, the
message ``You have new mail'' is given. If given while editing a
mailbox file with the -f flag, then the edit file is rewritten.
A return to the Shell is effected, unless the rewrite of edit
file fails, in which case the user can escape with the exit com-
mand.
reply (r) Takes a message list and sends mail to the sender and all
recipients of the specified message. The default message must
not be deleted. (See the Reply command and the Replyall vari-
able.)
respond
A synonym for reply.
retain Add the list of header fields named to the retained list. Only
the header fields in the retained list are shown on your terminal
when you print a message. All other header fields are sup-
pressed. The Type and Print commands can be used to print a mes-
sage in its entirety. If retain is executed with no arguments,
it lists the current set of retained fields. Retain overrides
save.
reverse
Reverse the order of the messages in at the current thread level.
This is completely equivalent to ``sort !''.
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.
set (se) With no arguments, prints all variable values. Otherwise,
sets option. Arguments are of the form option=value (no space
before or after =) or option. Quotation marks may be placed
around any part of the assignment statement to quote blanks or
tabs, i.e. ``set indentprefix="->"'' Inside single quotes every-
thing is parsed literally, including `\' escaped characters.
Inside double quotes `\' character escapes are interpreted. This
is an extension as POSIX specifies that `\' should be left unin-
terpreted for both single and double quoted strings.
saveignoreSaveignore is to save what ignore is to print and type. Header
fields thus marked are filtered out when saving a message by save
or when automatically saving to mbox.
saveretainSaveretain is to save what retain is to print and type. Header
fields thus marked are the only ones saved with a message when
saving by save or when automatically saving to mbox. Saveretain
overrides saveignore.
shell (sh) Invokes an interactive version of the shell.
show (sho) Takes a list of variables and prints out their values in
the form option=value. If the list is empty, all variable values
are shown.
showtags
Display all current messages, tagged or not, unless they are in a
hidden thread.
showthreads
The same as expose.
size Takes a message list and prints out the size in characters of
each message.
smopts Takes an ``address-spec'' followed by the sendmail flags that
should be used when sending mail to an address that matches that
``address-spec''. If no sendmail flags are specified, then list
the sendmail flags in effect for the ``address-spec''. If the
``address-spec'' is also omitted, then list all smopts settings.
The ``address-spec'' may be an alias, address, domain (beginning
with a `@'), or subdomain (beginning with a `.'). If mail is
sent to multiple users, the sendmail flags are used only if the
flags are the same for each recipients. If smopts-verify is set,
then you will be asked to verify the sendmail flags (if there are
any) before the mail is sent. Address matching is case insensi-
tive and done from most specific to least.
For example if you have:
smopts mylist -F "List Maintainer"
smopts @NetBSD.org -f anon@somewhere.net -F "Anon Ymous"
smopts friend@NetBSD.org ""
then mail sent to any of the addresses that the `mylist' alias
expands to would have the sender's name set to `List Maintainer'.
Mail sent to anyone at NetBSD.org other than `friend@NetBSD.org'
would look like it was sent from `anon@somewhere.net' by `Anon
Ymous'. Mail sent to `friend@NetBSD.org' would not have any
sendmail flags set (unless they are set by the ~h escape).
sort With no argument, sort does nothing. Otherwise it will sort
based on the header field name given as an argument. A few names
are special:
blines sort based on the number of body lines.
hlines sort on the number of header lines.
tlines sort on the total number of lines.
size sort on the message size
sday sent day (ignores the hour/min/sec)
rday received day (ignores the hour/min/sec)
sdate sent date
rdate received date
subject sort on the subject, ignoring "Re:" prefixes.
from sort on the sender's address.
The check for these special names is case sensitive while the
header field name comparisons are case insensitive, so changing
the case on any of these special names will sort based on the
header field ignoring the special keyword.
There are also three modifiers which may precede the argument:
! reverse the sorting order.
^ case insensitive sorting.
- skin the field (removing RFC 822 comments and
keep the address).
The same keywords and modifiers also apply to threading. (See
the thread command.)
Note: sort has no effect on the threading, sorting only on the
heads of the threads if threads exist.
source The source command reads commands from a file.
tag Tag a list of messages or the current message if none are given.
In hidden thread mode, the entire thread will be tagged, i.e.,
tag is recursive
tagbelow
Tag all messages of the current thread below the level of the
current message (dot) or the supplied message number if given.
thread By default this threads the current message list based on the
`In-Reply-To' and `References' header fields (intended for this
purpose by RFC 2822). If given an argument, it will thread on
that header field name instead. The same field keywords and mod-
ifiers recognized by the sort command are also recognized here.
Display of the threads is controlled by the hide and expose com-
mands; navigation of threads is done with the down, up, and tset
commands.
If recursive-commands is defined, many commands (e.g., print) act
on the entire thread (when it is hidden), otherwise they act on
just the current message.
Note: the `In-Reply-To' and `Reference' header fields are neces-
sary to do threading correctly. This version of mail now emits
these header fields when replying.
top Takes a message list and prints the top few lines of each. The
number of lines printed is controlled by the variable toplines
and defaults to five.
tset Set the current thread (thread set) so that the supplied message
number (or the current message if no argument is given) is at the
top level of the current thread.
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 message as not being
deleted.
unread (unr) Takes a message list and marks each message as not having
been read.
unset Takes a list of option names and discards their remembered val-
ues; the inverse of set.
unsmopts
Takes a list of ``address-specs'' defined by smopts commands and
discards them from the smopts database.
untag Untag a list of messages or the current message if none are
given. Like the tag command, untag is recursive on hidden
threads.
unthread
Undo all threading and sorting, restoring the original display
order, i.e., the order in the mail file.
up Go up one level in the thread. This also takes an optional (pos-
itive) argument to go up multiple levels in the thread.
view (vie) Like print but has the opposite MIME decoding behavior.
(See the mime-decode-message variable.)
visual (v) Takes a message list and invokes the display editor on each
message.
write (w) Similar to save, except that only the message body (without
the header) is saved. Extremely useful for such tasks as sending
and receiving source program text over the message system.
xit (x) A synonym for exit.
z mail presents message headers in windowfuls as described under
the headers command. You can move mail's attention forward to
the next window with the z command. Also, you can move to the
previous window by using z-.
Tilde/Escapes
Here is a summary of the tilde escapes, which are used when composing
messages to perform special functions. Tilde escapes are only recognized
at the beginning of lines. The name ``tilde escape'' is somewhat of a
misnomer since the actual escape character can be set by the option
escape.
~!command
Execute the indicated shell command, then return to the message.
~@ [filelist]
Add the files in the white-space delimited filelist to the
attachment list. If filelist is omitted, edit the attachment
list, possibly appending to it: For each file in the list the
user is prompted to change its attachment data. Changing the
filename to empty will delete it from the list. Upon reaching
the end of the attachment list, the user is prompted for addi-
tional files to attach until an empty filename is given. File-
names containing white-space can only be added in this ``edit''
mode.
~a Inserts the autograph string from the sign= option into the mes-
sage.
~A Inserts the autograph string from the Sign= option into the mes-
sage.
~bname ...
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).
~cname ...
Add the given names to the list of carbon copy recipients.
~d Read the file ``dead.letter'' from your home directory into the
message.
~e Invoke the text editor on the message collected so far. After
the editing session is finished, you may continue appending text
to the message.
~fmessages
Read the named messages into the message being sent. If no mes-
sages are specified, read in the current message. Message head-
ers currently being ignored (by the ignore or retain command) are
not included.
~ Identical to ~f, except all message headers are included.
~h Edit the message header fields, and the options passed to send-
mail (the Smopts), 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. If editline(3) sup-
port is included, then that line editor is used.
~istring
Inserts the value of the named option into the text of the mes-
sage.
~mmessages
Read the named messages into the message being sent, indented by
a tab or by the value of indentprefix. If no messages are speci-
fied, read the current message. Message headers currently being
ignored (by the ignore or retain command) are not included.
~Mmessages
Identical to ~m, except all message headers are included.
~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.
~x Exits as with ~q, except the message is not saved in
``dead.letter''.
~rfilename~<filename
Reads the named file into the message. If the argument begins
with `!', the rest of the string is taken as an arbitrary system
command and is executed, with the standard output inserted into
the message.
~sstring
Cause the named string to become the current subject field.
~tname ...
Add the given names to the direct recipient list.
~v Invoke an alternative editor (defined by the VISUAL option) on
the message collected so far. Usually, the alternative editor
will be a screen editor. After you quit the editor, you may
resume appending text to the end of your message.
~wfilename
Write the message onto the named file.
~|command
Pipe the message body through the command as a filter. If the
command gives no output or terminates abnormally, retain the
original text of the message. The command fmt(1) is often used
as command to rejustify the message.
~:mail-command
Execute the given mail command. Not all commands, however, are
allowed.
~~string
Insert the string of text in the message prefaced by a single ~.
If you have changed the escape character, then you should double
that character in order to send it.
Mail Options
Options are controlled via set and unset commands. Options may be either
binary, in which case it is only significant to see whether they are set
or not; or string, in which case the actual value is of interest. The
binary options include the following:
append Causes messages saved in mbox to be appended to the end rather
than prepended. This should always be set (perhaps in
/etc/mail.rc).
ask, asksub
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.
autoinc
Causes new mail to be automatically incorporated when it arrives.
Setting this is similar to issuing the inc command at each
prompt, except that the current message is not reset when new
mail arrives.
askbcc Causes you to be prompted for additional blind carbon copy recip-
ients 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 delet-
ing a message, the next one will be typed automatically.
crt If crt is set, then the PAGER will be used for the print, Print,
type, and Type commands. Normally these commands do not invoke
the pager. (See page-also.)
debug Setting the binary option debug is the same as specifying -d on
the command line and causes mail to output all sorts of informa-
tion useful for debugging mail.
dot The binary option dot causes mail to interpret a period alone on
a line as the terminator of a message you are sending.
enable-pipes
If defined, the output of most commands can be piped into a shell
command or redirected to a file. The pipe/redirection is sig-
naled by the first occurrence of a `|' or `>' character that is
not in a quoted string or in a parenthetical group. This charac-
ter terminates the mail command line and the remaining string is
passed to the shell. For example, assuming normal headers, some-
thing like
from john@ | fgrep -i ' "Re:' | wc
could be used to count how may replies were made by senders with
`john@' in their address and
from john@ >> /tmp/john
would append all the headers from such senders to /tmp/john.
Note: With piping enabled, you cannot use the `|' as a logical
``or'' operator outside of a parenthetical group. This should
not be a problem as it is the default logical operator. (See the
Specifying messages section.)
hold This option is used to hold messages in the system mailbox by
default.
ignore Causes interrupt signals from your terminal to be ignored and
echoed as @'s.
metoo Usually, when a group 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.
mime-attach-list
If set, the command line flag -a will accept a whitespace delim-
ited list of files. Otherwise, its argument is interpreted as a
single filename. Warning: If enabled, care must be taken to
properly quote files that contain whitespace, both from the shell
and from this second expansion done by mail.
mime-decode-header
If set, decode the headers along with the body when
mime-decode-message is set. The header decode follows the same
rules as the body (see mime-decode-message).
mime-decode-insert
When inserting a message into the mail buffer (~f or ~F), the
text inserted will be decoded according to the settings of the
mime-decode-message and mime-decode-header variables.
mime-decode-message
If set, the More, more, Page, page, Print, print, Type, and type
commands will display decoded the MIME messages. Otherwise, they
display the undecoded message. Recall that the View and view
commands always have the opposite MIME decoding behavior from
these commands.
mime-decode-quote
When quoting a message into the mail buffer (~m or ~M), the text
inserted will be decoded according to the settings of the
mime-decode-message and mime-decode-header variables.
mime-detach-batch
If set, the detach command does not prompt for anything (unless
mime-detach-overwrite is set to `ask'), overwriting target files
depending on the setting of mime-detach-overwrite.
noheader
Setting the option noheader is the same as giving the -N flag on
the command line.
nosave Normally, when you abort a message with two RUBOUT (erase or
delete) mail copies the partial letter to the file
``dead.letter'' in your home directory. Setting the binary
option nosave prevents this.
page-also
A comma or whitespace delimited list of additional commands to
page. The comparisons are case insensitive, so if view is in the
list, both view and View will page.
pager-off
If set, disable the pager on all commands.
quiet Suppresses the printing of the version when first invoked.
recursive-commands
When defined, and threading is in effect, the following commands
operate on the entire thread (if it is ``hidden'') rather than
just the top displayed message of the thread:
More Page Print Type View more page print type view
top
Save copy save write
Detach detach
delete dp dt
undelete
hold preserve
mbox mkread touch unread
tag untag invtags
If not defined, or if the threads are ``exposed'', commands
behave exactly as they do in non-threaded mode, i.e., each oper-
ates on individual messages.
Replyall
Reverses the sense of reply and Reply commands.
searchheaders
If this option is set, then a message-list specifier in the form
``/x:y'' will expand to all messages containing the substring
``y'' in the header field ``x''. The string search is case
insensitive. If ``x'' is omitted, it will default to the
`Subject' header field. If ``y'' is omitted, only those messages
that contain the field ``x'' will be matched. The three forms
``/from:y'', ``/to:y'', and ``/body:y'' are special. The first
will match all messages which contain the substring ``y'' in the
headline (which is added locally at receipt time and begins with
``From ''). The second will match all messages containing the
substring ``y'' in the `To', `Cc', or `Bcc' header fields. The
third will match all messages which contain the substring ``y''
in a line of the message body. The check for ``from'', ``to'',
and ``body'' is case sensitive, so that ``/From:y'' and ``/To:y''
can be used to search the `From' and `To' fields, respectively.
(See also regex-search.)
smopts-verify
Verify the sendmail options used on outgoing mail if they were
obtained from a smopts match. This has no effect if there are no
sendmail flags or if the flags were set by the ~h escape.
verbose
Setting the option verbose is the same as using the -v flag on
the command line. When mail runs in verbose mode, the actual
delivery of messages is displayed on the user's terminal.
Option String Values
EDITOR Pathname of the text editor to use in the edit command and
~e escape. If not defined, then a default editor is used.
LISTER Pathname of the directory lister to use in the folders com-
mand. Default is /bin/ls.
PAGER Pathname of the program to use in the more command or when
crt variable is set. The default paginator more(1) is used
if this option is not defined.
SHELL Pathname of the shell to use in the ! command and the ~!
escape. A default shell is used if this option is not
defined.
VISUAL Pathname of the text editor to use in the visual command
and ~v escape.
el-completion-keys
A comma or space delimited list of keys to do editline(3)
completion. For example set el-completion-keys=^I,^D will
bind completion to both the tab and CTRL-D keys. (Requires
editline(3) support.)
el-editor The line editing mode: must be `emacs' or `vi'. If unset,
editing is not enabled. (Requires editline(3) support.)
el-history-size
The number of lines of history to remember. If unset, his-
tory is not enable. (Requires editline(3) support.)
escape If defined, the first character of this option gives the
character to use in the place of ~ to denote escapes.
folder The name of the directory to use for storing folders of
messages. If this name begins with a `/', mail considers
it to be an absolute pathname; otherwise, the folder direc-
tory is found relative to your home directory.
header-format
If set, use this format string when displaying headers in
command mode. The format string supports the following
conversions in addition to those of strftime(3):
%?key? The header field with name `key'. Note: if key[0]
is `-', ignore the `-' and extract the address por-
tion of the field (i.e., ``skin'' the field).
%?*string?
If the depth is n, substitute `string' n times.
This is intended to be used when displaying an
``exposed thread''.
%?&string?
Like %?*string?, but uses the depth relative to the
current depth rather than the absolute depth.
%J The number of header lines in the message.
%K The number of body lines in the message.
%L The total number of lines in the message.
%N The sender's full name (as in the `From' or
`Sender' fields).
%O The message size.
%P The current ``dot'' (`>') message.
%Q The message status flag.
%Z The time zone name (if it exists).
%f The email address of sender.
%i The message number.
%n The sender's login name (taken from the address).
%q The subject.
%t The total number of messages.
%z The GMT offset (if found).
If the format string begins with `%??' then the date will
be extracted from the headline. Otherwise it will be
extracted from the `Date' header falling back to the head-
line if that extraction fails. For example, the default
format is:
set header-format="%??%P%Q%?* ?%3i %-21.20f %a %b %e %R %3K/%-5O \"%q\""
Note 1: The message status flag `%Q' will display the sin-
gle character `+' for the parent of a subthread. This will
be overwritten by a `T', `E', `*', `P', `U', `N', `M' indi-
cating, respectively, a tagged, modified, saved, preserved,
unread, new, or modified message, in that order with the
last matching condition being the one displayed. In the
case of hidden threads, the entire subthread is searched
and the letters above will be displayed in lower case if
the property is that of a hidden child with the case `*'
being displayed as `&'.
Note 2: %n and %t as used by strftime(3) were redundant
with \t and \n, respectively, so nothing is lost using them
here.
ignoreeof An option related to dot is ignoreeof which makes mail
refuse to accept a `control-D' as the end of a message. If
given a numeric argument n, a `control-D' will be accepted
after n tries. Ignoreeof also applies to mail command
mode.
indentpreamble
If set, this format string will be inserted before quoting
a message (~m or ~M). The format syntax is the same as for
header-format. For example, the following:
set indentpreamble=
"On %b %e %T, %Y %z (%Z), %n (%.50N) wrote:\n-- Subject: %.65q\n"
would insert something like
On Oct 27 11:00:07, 2006 -0400 (EDT), anon (Anon Ymous) wrote:
-- Subject: suggestions for mail(1)
before the quoted message.
indentprefix String used by the ~m and ~M tilde escapes for indenting
messages, in place of the normal tab character (`^I'). Be
sure to quote the value if it contains spaces or tabs.
indentpostscript
If set, this format string will be inserted after quoting a
message (~m or ~M). The format syntax is the same as for
header-format. For example, the following:
set indentpostscript="-- End of excerpt from %.50N"
would insert something like
-- End of excerpt from Anon Ymous
after the quoted message.
mime-body-TYPE-SUBTYPE
MIME-hook for the body of a MIME block of `Content-Type:
TYPE/SUBTYPE'. (See MIME Enhancements below.)
mime-charset Convert `Content-type: text' messages to this character set
or `us-ascii' if the value is empty. If unset, no charac-
ter set conversion is done.
mime-detach-dir
The directory to detach files to if the detach command is
given no arguments. (See detach.)
mime-detach-overwrite
This controls overwriting of existing files by the detach
command. If set to `ask' the user will be prompted before
overwriting a file. If set to `yes', or to the empty
string, existing target files will be overwritten. If set
to `no', no target files will be overwritten.
mime-encode-message
If set, encode the body of the message as required. Typi-
cally, this is just an issue of whether `quoted-printable'
encoding is used or not. If it has a value, then use it to
determine the encoding type. Allowed values are `7bit',
`8bit', `binary', `quoted-printable', or `base64'.
mime-head-TYPE-SUBTYPE
MIME-hook for the header of a MIME block of `Content-Type:
TYPE/SUBTYPE'. (See MIME Enhancements below.)
mime-hook-TYPE-SUBTYPE
MIME-hook for MIME block of `Content-Type: TYPE/SUBTYPE'.
(See MIME Enhancements below.)
MBOX The name of the mbox file. It can be the name of a folder.
The default is ``mbox'' in the user's home directory.
prompt If defined, it specifies the prompt to use when in command
mode. Otherwise, the default `&' is used. The format syn-
tax is the same as for header-format.
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.
regex-search If set, regular expression searches are used, instead of
simple case insensitive substring matches, when determining
message lists by searching sender names, subjects, or
header fields (if searchheaders is defined); see the
Specifying messages section. The value of the variable is
a space or comma delimited list of options. Valid options
are `icase' to do case insensitive searches, `extended' to
use extended (rather than basic) regular expressions, and
`nospec' to turn off all special character meanings and do
literal string searches. Note that `extended' and `nospec'
are not compatible (see regcomp(3)).
ReplyAsRecipient
This is used when replying to email (see the reply or Reply
commands). It is useful if you have multiple email
addresses and wish to ensure that replies respect them. If
set, grab the email address(es) from the `To' field of the
message being replied to. If there is only one such
address, and if it does not match any address in the value
of ReplyAsRecipient (a comma or space delimited list of
addresses, possibly empty), then use this address in the
`From' field of the reply. This is accomplished by passing
the address to sendmail(1) with the -f option. Note: the
sendmail options can be edited with the ~h escape. (See
also the smopts command.)
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.
MIME Enhancements
A MIME message is (recursively) divided into a series of MIME parts that
can be thought of as sub-messages, each with a header and body. When
MIME support is enabled (by setting mime-decode-message), mail splits a
message into a series of its smallest MIME parts and processes those
parts as if they were messages themselves, passing the header and body
through a pipeline of the form:
mail -> MIME-decoder -> MIME-hook -> pager -> screen
The MIME-decoder decodes `base64' or `quoted-printable' encoding and is
enabled according to the `Content-Transfer-Encoding' of the part. The
MIME-hook is an external program to further process the part (see below).
The pager is the program that pages the message (see PAGER). Any of
these intermediate pipe stages may be missing and/or different for the
head and body of each MIME part. Certain `Content-Types' may disable the
entire pipeline (e.g., `application/octet').
The MIME-hook stage is not present unless one of the following variables
is set:
mime-hook-TYPE-SUBTYPE applies to the entire MIME part
mime-head-TYPE-SUBTYPE applies to the header of the MIME part
mime-body-TYPE-SUBTYPE applies to the body of the MIME part
where TYPE and SUBTYPE are the `Content-Type' type and subtype (respec-
tively) of the MIME part to which the hook applies. If the ``-SUBTYPE''
is missing, any subtype is matched. The value of these variables has the
format:
[flags] command
where the command is expected to read from stdin and write to stdout, and
the possible flags are
! Execute command in a sub-shell rather than doing an exec(3)
(see SHELL).
+ Use this hook when selecting the part to display in a
`multipart/alternative' block. Multipart blocks contain
``alternative'' versions with the same information, in
increasing order of preference (and decoding complexity).
The last one the mail agent understands is the one to be
displayed. This is typically used for sending a message in
both ``plain text'' and ``html'', but more complex subtypes
are also possible.
- Do not decode before executing command.
If your command begins with one of these flags, precede it with a space
to signal the end of the flags.
WARNING: automatically running a program is a potential security risk if
that program has bugs, so be careful what you run.
Examples: View all `Content-Type: image/jpeg' parts with xv(1) (assuming
it is installed):
set mime-body-image-jpeg="/usr/pkg/bin/xv -"
Decode all `Content-Type: images/*' blocks with uudeview(1) (assuming it
is installed), placing the results in /tmp:
set mime-hook-image="-/usr/pkg/bin/uudeview -p /tmp -i -a +o -q -"
Read all `Content-Type: text/html' parts using lynx(1) (assuming it is
installed) and add this support to `multipart/alternative' blocks:
set mime-body-text-html="+/usr/pkg/bin/lynx -force_html -dump -stdin"
ENVIRONMENTmail uses the HOME, TMPDIR, and USER environment variables.
FILES
/var/mail/* Post office. This can be overwritten by set-
ting the MAIL environment variable.
~/mbox User's old mail. This can be overwritten by
setting the MBOX environment variable.
~/.mailrc File giving initial mail commands. This can
be overridden by setting the MAILRC environ-
ment variable.
/tmp/mail.R* Temporary files.
/usr/share/misc/mail.*help Help files.
/etc/mail.rc System initialization file.
SEE ALSOfmt(1), newaliases(1), sendmail(1), vacation(1), aliases(5), mailaddr(7)
and
The Mail Reference Manual.
HISTORY
A mail command appeared in Version 6 AT&T UNIX. This man page is derived
from ``The Mail Reference Manual'' originally written by Kurt Shoens.
BUGS
There are some flags and commands that are not documented here. Most are
not useful to the general user.
Usually, mail is just a link to Mail, which can be confusing.
The name of the alternates list is incorrect English (it should be
``alternatives''), but is retained for compatibility.
There must be sufficient space on $TMPDIR for various temporary files.
If an unrecoverable character set conversion error occurs (during dis-
play), the message is truncated and a warning is printed. This seems to
be rare, but probably the remainder of the message should be printed
without conversion.
The internal sh-like parser is not terribly sh-like.
Selecting messages by their content (i.e., with `/body:') is rather slow.
NetBSD 8.0 December 15, 2014 NetBSD 8.0

You can also request any man page by name and (optionally) by section:

Command:

Section:

Architecture:

Collection:

Use the DEFAULT collection to view manual pages
for third-party software.