Read or send mail messages (POSIX)
mailx [-s subject] address...
mailx [-eFHinN] [-f [file]] [-u user]
- -e
- Test for the presence of mail. If there is mail to read, mailx
prints nothing and exits with a successful return code.
- -f [file]
- Read messages from the named file instead of from the
mailbox. If no file is specified, the mbox is used, which
defaults to mbox in your home directory.
- -F
- Record the message in a file named after the first recipient. This option
overrides the record variable.
- -H
- Display a header summary only.
- -i
- Ignore interrupts.
- -n
- Don't initialize from the system default mailx.rc
file.
- -N
- Don't display an initial header summary.
- -s subject
- Set the Subject header field to subject.
- -u user
- Read the named user's mailbox. Without appropriate privileges, you can
read only your own mailbox.
- address
- The address passed to the mail delivery software.
The mailx utility is an interactive program that lets
you receive, compose, and send messages. When you read mail, mailx
provides commands that let you browse, save, delete, and answer messages.
When you send mail, mailx lets you interactively review
and edit your messages; you can also include text from files and other
messages.
When you start mailx, it reads commands from the
/usr/lib/mailx.rc file to initialize certain parameters.
It then reads from a private startup file to get your personal commands and
variable settings. This private startup file is normally called
.mailrc and resides in your home directory (you can
specify another pathname with the MAILRC environment variable).
You can place most mailx commands in your startup file
(the ones most commonly used are those to set up initial display options
and alias lists). Note, however, that you can't use the following
commands:
!
Copy
edit
Followup
followup
hold
mail
preserve
Reply
reply
shell
visual
If an error is found in the startup file, all the remaining lines are ignored.
If you specify no recipients when you invoke mailx, it
enters command mode. If you have no unread messages, mailx
will print the following message and then exit:
No mail for username
If mail is waiting, however, you'll first see a header summary of
the first several messages, followed by a prompt indicating that you
can enter regular commands (described below). By default, the prompt
is &, but you can choose another one with the prompt
variable.
Each message is assigned a number. At any time, there is a
current message, which is marked by a > in the
header summary. To read this message, you can use the print command
(which you can abbreviate to a simple p).
Many commands, including the print command, let you specify
an optional list of messages (msglist) to work on. If
you omit the msglist, the command applies to the current
message. A msglist is a list of message specifications,
separated by spaces, which can include:
Message Specification |
Meaning |
n
|
message number n |
.
|
the current message |
^
|
the first undeleted message, or the first deleted message for the
undelete command |
$
|
the last 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 |
|
Valid types of messages for :type message specs are:
- d
- deleted messages
- n
- new messages
- o
- old messages
- r
- read messages
- u
- unread messages
The context of the command determines whether this type of
message specification makes sense. |
Additional arguments are usually strings whose usage depends on the
command involved. Filenames, where expected, can be specified with
metacharacters understood by the Shell. Some commands recognize special
characters; these are documented with the commands below.
Incoming mail is stored in a separate file for each user, called a
mailbox. When you use mailx to read messages,
it looks in your mailbox by default. As you read messages, they are
marked to be moved to a secondary file for storage, unless you take
action otherwise. The secondary file, called the mbox,
is normally located in your home directory. Messages remain in this
file until you explicitly remove them.
To send mail, you can invoke mailx with the user names
of the people you wish to send to -- this puts mailx
in input mode and you can begin typing in your message. If
you didn't specify any subject via option -s when invoking
mailx, you'll be prompted for a subject, provided that
the asksub variable is set. Once you've entered your
subject, mailx enters input mode and you can begin typing.
As you type your message, mailx stores it in a temporary
file. To review or modify the message, you can use the tilde
(~) escape commands described below. To submit your message, you
enter either of the following on a line by itself:
~. or .
When you indicate your message is complete, your message is routed to each
recipient.
The "Commands" and "Tilde escapes" sections below describe all the commands
available in mailx. If you're a new user, the following table
lists the basic commands you'll use most often:
In order to: |
Use: |
display a message |
print |
reply to a message |
reply or respond |
forward a message (input mode) |
~f |
delete a message |
delete |
restore a message deleted in the current session
|
undelete or exit |
end a mail session |
quit |
create distribution lists so you can send mail to groups of people
|
alias |
display a summary of commands |
? |
display a summary of tilde escape commands (input mode)
|
~? |
You can modify how mailx behaves through a set of variables.
These are flags and valued parameters that you set and clear via the
set and unset commands. These variables are described
under "Internal variables," below.
- !command
- Escape to the shell.
- # comment
- Null command (comment).
- =
- Display the current message number.
- ?
- Display a summary of commands.
- a[lias] alias name...
- Declare an alias for the given list of recipients. The names will be
substituted when alias is named as a recipient.
- alt[ernates] name...
- Declare 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 displays
the current list of alternate names.
- cd [directory]
ch[dir] [directory]
- Change directory. If a directory isn't specified, your home directory
is used.
- C[opy] [msglist]
- Save the specified messages in a file whose name is derived
from the author of the message. The messages aren't marked as saved.
Otherwise equivalent to the Save command.
- c[opy] [file]
c[opy] [msglist] file
- Copy messages to the named file without marking the messages as saved.
If a message list isn't specified, the current message is used. Otherwise
equivalent to the save command.
- d[elete] [msglist]
- Delete messages from mailbox. If autoprint
is set, print the message following the last deleted message.
- di[scard] [header-field...]
- When displaying messages, don't print the specified header
fields (e.g. Message Id, Received,
...). The fields are included when the message is saved. The Print
and Type commands override this command.
- dp [msglist]
dt [msglist]
- Delete the specified messages from the mailbox and
print the message following the last deleted message. This is roughly
equivalent to a delete command followed by a print
command.
- ec[ho] string...
- Echo the given strings.
- e[dit] [msglist]
- 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.
(Default: vi)
- ex[it]
- Exit from mailx without changing the mailbox. No messages are
saved in the mbox (see also quit).
- fi[le] [file]
fold[er] [file]
- Quit from the current file of messages and read in the named mailbox
file. Instead of specifying a filename, you can also use one of the
following:
- %
- the current mailbox
- %user
- the mailbox for user
- #
- the previous file
- &
- the current mbox
- +file
- the named file in the folder directory (see
the folder variable)
All of these special forms are recognized when used for
any file arguments for mailx commands, tilde escapes,
or the -F option. The default file is the current
mailbox.
- folders
- Display the names of the files in the directory set by the
folder variable.
- F[ollowup] [msglist]
- Respond to the first message in msglist, sending
the message to the author of each message in the
msglist. The subject line is taken from the first
message and the response is recorded in a file whose name is derived
from the author of the first message. See also the Copy,
followup, and Save commands as well as the
outfolder variable.
- fo[llowup] [message]
- Respond to a message, recording the message in a file whose name is derived
from the author of the message. The subject line is taken from the
subject of the first message. See also the Copy,
Followup, and Save commands as well as the
outfolder variable.
- f[rom] [msglist]
- Display the header summary for the specified messages (default
is the current message).
- g[roup] aliasname...
- Same as the alias command.
- h[eaders] [message]
- Display the page of headers that includes the specified message.
The screen variable sets the number of headers per page.
See also the z command.
- hel[p]
- Display a summary of commands.
- ho[ld] [msglist]
- Hold the specified messages in the mailbox.
- i[f] s|r
mail-commands
el[se] mail-commands
en[dif]
- Conditional execution, where: s executes the following
mail-commands, up to an else or
endif, if the program is in send mode,
and r causes mail-commands
to be executed only in receive mode.
- ig[nore] header-field...
- Same as the discard command.
- l[ist]
- Display all commands available. No explanations are given.
- m[ail] name...
- Mail a message to the named users.
- mb[ox] [msglist]
- Arrange for the given messages to end up in the standard
mbox save file when mailx terminates normally.
For a description of this file, see the MBOX variable.
See also the exit and quit commands.
- n[ext] [message]
- Go to the next message that matches message. You
could specify a message list, but note that in this case the first
valid message in the list is the only one used. See the discussion
of msglists above for a description of possible
message specifications.
- pi[pe] [msglist] [command]
|[msglist] command
- Pipe the message through the given command. The
command can be given options. The message is treated as if it were read.
If no arguments are given, the current message is piped through the
command specified by the cmd variable. If the page
variable is set, a form-feed character is inserted
after each message.
- pre[serve] [msglist]
- Same as the hold command.
- P[rint] [msglist]
- Display the specified messages. All header lines are displayed, including
any otherwise suppressed by the ignore and discard
commands.
- p[rint] [msglist]
- Display the specified messages. If the crt variable is set,
any messages longer that the number of lines specified by crt
are paged through the command specified by the PAGER variable.
- q[uit]
- Exit from mailx, and do the following:
- store messages that were read in mbox (unless hold is set)
- delete messages that have been explicitly saved (unless
keepsave is set)
- discard messages that have been deleted
- save all remaining messages in the mailbox
- R[eply] [msglist]
R[espond] [msglist]
- Send a response to the author of each message in the
msglist. The subject line is taken from the first
message. If record is set to a filename, the response is
appended to that file.
- r[eply] [message]
r[espond] [message]
- Reply to the specified message, including all other recipients of the
message. The subject line is taken from the subject of the first message.
If record is set to a filename, the response is appended to
that file.
- S[ave] [msglist]
- 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 to be the
author's name. See also the Copy, Followup,
and followup commands as well as the outfolder
variable.
- s[ave] [file]
s[ave] [msglist] file
- Save the specified messages in the named file. If the file doesn't exist,
it will be created. The message is deleted from the
mailbox when mailx terminates unless
the keepsave variable is set. See also the exit and
quit commands.
- s[et]
se[t] name
se[t] name=string
se[t] name=number
se[t] noname
- Define a variable called name. You can give the
variable a null, string, or numeric value. Quoting and backslash escapes
can occur anywhere in string. If you use
set by itself, it displays all defined variables and their
values. See the section on "Internal variables"
for a description of all predefined variables.
- sh[ell]
- Invoke the Shell. See also the SHELL variable.
- si[ze] [msglist]
- Display in bytes the size of the specified messages.
- so[urce] file
- Read commands from the named file and return to command mode.
- to[p] [msglist]
- Display the top few lines of the specified message (default is 5). You
can use the toplines variable to determine the number of
lines to be displayed.
- tou[ch] [msglist]
- Touch the specified messages. If any message in
msglist isn't specifically saved in a file, it
is placed in the mbox upon normal termination. See also the
exit and quit commands.
- T[ype] [msglist]
- Same as the Print command.
- t[ype] [msglist]
- Same as the print command.
- u[ndelete] [msglist]
- Restore the specified deleted messages. This command restores only
those messages deleted in the current mail session. If the
autoprint variable is set, the last message restored is
displayed.
- uns[et] variable...
- Erase the specified variables. You cannot erase a variable that was
imported from the execution environment (i.e. an environment variable).
- ve[rsion]
- Display the current version and release date of mailx.
- v[isual] [msglist]
- Edit the given messages with a screen editor. The messages are placed
in a temporary file and the VISUAL variable is used to get
the name of the editor.
- w[rite] [msglist] file
- Write the given messages to the named file, minus the header lines and
the following empty line. Otherwise equivalent to the save
command.
- x[it]
- Same as the exit command.
- z[+|-]
- Scroll the header display forward or backward one screenful.
The number of headers displayed is set by the screen
variable.
You can enter the following commands only in input mode. To type a
tilde character (~) as text, enter it twice. To change
this special character, see the escape variable.
- ~! command
- Escape to the Shell.
- ~.
- Simulate end of file (terminate message input).
- ~: mail-command
~_ mail-command
- Perform the specified command. This is valid only when you're
sending a message while reading mail.
- ~?
- Display a summary of tilde escapes.
- ~A
- Insert the autograph string Sign into the message
(see "Internal variables").
- ~a
- Insert the autograph string sign into the message
(see "Internal variables").
- ~b name...
- Add the specified names to the blind carbon copy (Bcc) list.
- ~c name...
- Add the specified names to the carbon copy (Cc) list.
- ~d
- Read in the dead.letter file. For a description
of this file, see the DEAD variable.
- ~e
- Invoke the editor to edit the partial message. The editor
to be used is determined by the EDITOR variable.
- ~f [msglist]
- Forward the specified messages. The messages are inserted
into the message, without alteration.
- ~h
- Prompt for Subject line and To, Cc, and Bcc lists. If the
field is displayed with an initial value, you can edit it as if had
just been typed.
- ~i string
- Insert the value of the named variable into the text of
the message. For example, specifying ~iSign is the same
as specifying ~A.
- ~m [msglist]
- Insert the specified messages into the letter, shifting the new text one
tab stop to the right. This is valid only when you're sending a message
while reading mail.
- ~p
- Display the message being entered.
- ~q
- Quit from the input mode by simulating an interrupt. If the body of the
message isn't empty, the partial message is saved in the
dead.letter file. For a description of this file,
see the DEAD variable.
- r file
~<file
~<!command
- Read in the text of the named file or the standard output of the specified
command.
- ~s string
- Set the subject line to string.
- ~t name...
- Add the given names to the To list.
- ~v
- Invoke a visual editor to edit the partial message. The editor to be used
is determined by the VISUAL variable.
- ~w file
- Write the partial message to the named file, but don't include the header.
- ~x
- Exit as with ~q, but don't save the message in the
dead.letter file.
- ~| command
- Pipe the body of the message through the given command. If the command
returns successfully, the output of the command replaces the message.
Otherwise the message remains unchanged.
You can initialize the following variables within the .mailrc
file; you can also set or modify them with the set command
at any time. You can also import these variables from the execution
environment, if they are already set. To erase variables, you can use the
unset command. You can also erase variables using this command:
set novariable
which is equivalent to:
unset variable
Note that the following internal variables are initially assigned
values that are imported from the execution environment. Nevertheless,
those values can be overridden by assignments inside one of the startup
files: DEAD, EDITOR, MBOX, LISTER,
PAGER, SHELL, VISUAL.
- append
- Upon termination, append messages to the end of the mbox
file instead of prepending them. The default is noappend.
- askcc
- Prompt for the Cc list after the message is entered. The default is
noaskcc.
- asksub
- Prompt for the subject if it isn't specified on the command line with the
-s option. Enabled by default.
- autoprint
- Enable automatic display of messages after delete and
undelete commands. The default is noautoprint.
- bang
- Enable the special-case treatment of exclamation points (!)
in escape command lines (as in vi). The default is
nobang.
- cmd=command
- Set the default utility (including options) for the pipe
command. There is no default value.
- crt=number
- Pipe messages having more than number lines
through the command specified by the PAGER variable. Disabled
by default.
- DEAD=file
- The pathname of a file in which to save partial letters in case of
untimely interrupt or delivery errors. The default is
dead.letter in your home directory.
- dot
- Take a period on a line by itself during input from a terminal
as end-of-file. The default is nodot.
- EDITOR=utility
- The utility to run when the edit command or the ~e
command is used. Will default to the setting of the EDITOR
environment variable. If the environment variable isn't set,
"vi" will be used.
- escape=c
- Substitute the character c for the ~ escape
character.
- folder=directory
- The directory for saving standard mail files. User-specified filenames
beginning with a plus (+) are expanded by preceding
the filename with this directory name to obtain the real filename.
If directory doesn't start with a slash
(/), $HOME is prepended to it.
There is no default for folder. See also outfolder,
below.
- header
- Enable the display of the header summary when entering mailx.
Enabled by default.
- hold
- Preserve all messages that are read in the mailbox
instead of putting them in the standard mbox save
file. The default is nohold.
- ignore
- Ignore interrupts while entering messages. The 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. The default is noignore. See also dot.
- keep
- When the 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
mailbox instead of deleting them. The default is
nokeepsave.
- MBOX=file
- The pathname of a file to save message that have been read. The
xit command overrides this function, as does saving
the message explicitly in another file. The default is mbox
in your home directory.
- metoo
- If your login appears as a recipient, don't delete it from the recipient
list. The default is nometoo.
- LISTER=command
- The utility (including options) to use when listing the contents of the
folder directory. The default is the ls -C command.
- outfolder
- Place the files used to record outgoing messages in the directory
specified by the folder variable, unless an absolute pathname
is specified. The default is nooutfolder. See the
folder variable as well as the copy,
Followup, followup, and Save commands.
- page
- Used with the pipe command to insert a form-feed
after each message sent through the pipe. The default is nopage.
- PAGER=command
- The utility (including options) to use as a filter for paginating
output. The default is more.
- prompt=string
- Set the command mode prompt to string. The
default is an ampersand (&) followed by a
space.
- quiet
- Don't display the opening message and version when entering
mailx. The default is noquiet.
- record=file
- Record all outgoing mail in the named file. Disabled by default. See also
outfolder above.
- save
- Enable saving of messages in dead.letter on
interrupt or delivery error. Enabled by default. For a description
of this file, see DEAD.
- screen=number
- Set the number of headers per page for the headers command.
(Default: 20)
- SHELL=utility
- The name of your preferred shell. The default is sh.
- showto
- When displaying the header summary and if the message is from the user,
the recipient's name, not the author's name, is displayed following
To.
- Sign=string
- The variable inserted into the text of a message when the ~A
autograph command is given. No default (see also ~i in
"Internal variables").
- sign=string
- The variable inserted into the text of a message when the ~a
autograph command is given. No default (see also ~i in
"Internal variables").
- toplines=number
- The number of lines of header to display with the top
command. The default is 5.
- VISUAL=utility
- The name of your preferred screen editor.
Will default to the setting of the VISUAL
environment variable. If the environment variable isn't set,
"vi" will be used.
- HOME
- The pathname of your home directory.
- MAILRC
- The pathname of a startup file. The default is .mailrc
in your home directory.
The following environment variables influence the initial value of
some mailx internal variables: DEAD,
EDITOR, MBOX, LISTER,
PAGER, SHELL, VISUAL.
- 0
- Successful completion.
- >0
- An error occurred.