The mailx(1) utility is an electronic mail processing
utility that is similar to a line editor for mail, except that
lines are replaced by messages. The mailx(1) utility has two
basic modes of operation: reading mail and sending
mail. Each mode has its own commands and options. The first
synopsis line above is for sending mail.
To send mail, give the command mailx(1) and one or more
login names (for users on the same computer) or e-mail addresses.
The mailx(1) utility prompts for a message (unless one has
been supplied with the -s option), and then enters input
mode. All text typed into mailx(1) form part of the message
until you enter the end-of-file character or the command ~..
See "Sending and replying to mail" for a longer discussion; see
Tilde/Escapes for a list of the commands used in input mode.
To read mail, give the command mailx(1). The
mailx(1) utility displays a list of message headers, each
representing a message in your system mailbox. In this mode, you
can read, save, and delete mail messages. You can also reply or
send mail (dropping into input mode to do so), and set options to
control the behavior of mailx(1).
The mailx(1) utility takes the following options:
-blist
Send blind carbon copies to list. List should be a
comma-separated list of names. Normally, all recipients can see who
was sent a copy of the message. That information is suppressed in a
blind carbon copy, however, so that only the sender and the blind
carbon-copy recipient know about the copy.
-clist
Send carbon copies to list of users.
-e
Check for mail in the system mailbox and exit without printing
a message. If there is mail in the system mailbox, mailx(1)
returns an exit status of 0; otherwise, it returns an exit status
of 1. In a shell script or a startup file such as .profile,
this is useful for checking for the presence of mail.
-f[mbox]
Read in the contents of your mbox (or the specified
file) for processing; when you quit, mailx(1) writes
undeleted messages back to this file.
-H
Write a header summary only; this is only the first set of 18
messages, starting with the first unread message.
-i
Ignore tty interrupt signals. This is particularly useful when
using mailx(1) on noisy phone lines. You can also set this
behavior inside mailx(1) with the ignore option.
-I
Run mailx(1) in interactive mode even when input is not
a terminal. In particular, the tilde (~) special character,
when sending mail, is only active in interactive mode.
-n
Inhibits reading the system startup files /etc/mail.rc
and /etc/mailx.rc upon startup.
-N
Inhibit the initial display of message headers when reading
mail or editing a mail folder.
-ssubject
Specify subject on command line. (Only the first argument after
the -s flag is used as a subject; be sure to quote subjects
containing spaces.)
-uuser
Is equivalent to:
mailx -f /var/mail/user
You must have the appropriate permissions to read mail for
user.
-v
Verbose mode. The details of delivery are displayed on the
user's terminal.
To send a message to one or more people, mailx(1) can be
invoked with arguments that are the names of people to whom the
mail will be sent. You are then expected to type in your message,
followed by a CTRL+D at the beginning of a line. The section
"Replying to or originating mail" describes some features of
mailx(1) you can use to compose messages.
An e-mail address can be either a local address or an
Internet-style address. Internet-style addresses are of the form
name@domain; all other addresses are taken as local
addresses. (The mailx(1) utility does not recognize
UNIX-to-UNIX [UUCP]-style bang addresses or the %-hack.)
To read mail, give mailx(1) no arguments. It checks your
mail out of the post office, then prints out a one-line header for
each message found. Each message is numbered, and the message your
commands affect is called the current message. When you
start mailx(1), the current message is the first message,
message 1. You can display the message using the print
command (which can be abbreviated p). To make a new message
the current message, use the commands + and - to move
backwards and forwards in the list, or specify a message by number.
There are other ways of specifying which messages your commands
will act on; see "Specifying messages."
After you examine a message, you can delete (d the
message or reply (r) to it. Deletion causes the
mailx(1) program to forget about the message. This is not
irreversible; the message can be undeleted (u) by
giving its number; or the mailx(1) session can be aborted by
giving the exit (x) command (rather than the usual
quit command). Usually, deleted messages completely
disappear.
Commands such as print and delete can be given a
list of message numbers as arguments to apply to a number of
messages at once. Thus, delete 1 2 deletes messages 1 and 2;
delete 1-5 deletes messages 1 through 5. The special name
* addresses all messages, and $ addresses the last
message. The command top, which prints the first few lines
of a message, could be used in top * to print the first few
lines of all messages.
Following is a list of message specifications and their
explanations:
num
Message number num
n-m
Messages number n through m
*
All messages
.
The current message
+
The following appropriate message
-
The previous appropriate message
^
The first appropriate message in the list
$
The last message in the list
address
All messages from address (as shown in the header)
/string
All messages with string in the subject line (case is
ignored)
:c
All messages of type c, where c is one of the
following:
d
Deleted messages
n
New messages
o
Old messages (messages that are unread or new)
r
Read messages
u
Unread messages
The word "appropriate" is needed because although most commands
work only on undeleted commands, the undelete command only
works on deleted commands. So print ^ prints the first
undeleted message in the list; undelete ^ undeletes the
first deleted message in the list.
You can use the reply command to set up a response to a
message, sending it back to the person who sent it to you. The text
you then type in, up to an end-of-file, defines the contents of the
message. While you are composing a message, mailx(1) treats
lines beginning with the tilde character (~) specially. 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 later in this topic). 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 that follows.)
You can end a mailx(1) session with the quit
(q) command. Messages that 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 discussed previously in this topic.)
It is also possible to create a personal distribution lists so
that, for instance, you can send mail to cohorts or a defined group
of people. Such lists can be defined by placing a line such as the
following:
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 mailx(1). 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.
The mailx(1) utility includes a number of options that
can be set in the .mailrc file to alter its behavior; thus
set askcc enables the askcc feature. (These options are
summarized later in this topic.)
Each command is typed on a line by itself, and take arguments
following the command word. The general syntax is:
command [msg-list ] [arguments ]
The command need not be typed in its entirety; the first command
that matches the typed prefix is used. For commands that take
message lists as arguments, if no message list is given,
mailx(1) uses the next message forward that satisfies the
command's requirements. If there are no messages forward of the
current message, the search proceeds backwards. If there are no
good messages at all, mailx(1) types "No applicable
messages" and aborts the command.
-
Print out the preceding message. If given a numeric argument
n, goes to the occurrence of the previous message specified
by n and prints it.
?
Print a brief summary of commands.
!
Execute the shell (see sh(1) and csh(1)) command
that follows.
Print
(P) Like print but also print out ignored header
fields. (See also print, ignore and
retain.)
Reply
(R) Reply to sender. Does not reply to other recipients
of the original message.
Type
(T) Identical to the Print command.
alias
(a) With no arguments, print out all currently defined
aliases. With one argument, print out that alias. With more than
one argument, create a new alias or change an old one.
alternates
(alt) The alternates command is useful if you
have accounts on several computers. It can be used to inform
mailx(1) that the listed addresses are really you. When you
reply to messages, mailx(1) 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 alternate names is displayed.
chdir
(c) Changes the user's working directory to that
specified, if given. If no directory is given, then changes to the
directory specified in HOME.
copy
(co) Like save, the copy command saves a
file except that it does not mark the saved messages for deletion
when you quit.
delete
(d) Mark the messages in the list as deleted. Deleted
messages will not be saved in mbox, nor will they be
available for most other commands. They are not actually deleted
until you quitmailx(1). See undelete.
dp
(also dt) Delete the current message and print the next
message. If there is no next message, mailx(1) says at
end-of-file (EOF).
edit
(e) Edit each message in the supplied message list using
the editor specified in the EDITOR environment variable. On
return from the editor, the message is read back in.
exit
(ex or x) Effects an immediate return to the
shell without modifying the user's system mailbox, mbox
file, or edit file in -f.
file
(fi) The same as folder.
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.
#
The previous file
%
Your system mailbox
%user
The user's system mailbox
&
Your mbox file
+file
The named file in your folder directory (see the
folder option)
from
(f) Print the message headers of the messages in a
list.
headers
(h) List the current range of headers, which is an
18-message group. The argument + displays the next
18-message group, and the argument - displays the previous
18-message group.
help
A synonym for ?
hold
(b and preserve) Marks each message in a supplied
list to be saved in your system mailbox instead of in mbox.
Does not override the delete command.
ignore
Add the supplied list of header fields 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
commands Type and Print display a message in its
entirety, including ignored fields. If no arguments are given,
ignore lists the current set of ignored fields.
mail
(m) Send mail to the names specified as arguments; the
names can be login names or distribution group names.
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.
next
(n, like + or pressing ENTER). Goes to the next
message in sequence and types it. With an argument list, types the
next matching message.
preserve
(pre) A synonym for hold.
print
(p) Display on the user's terminal each message in the
message list.
quit
(q) Terminate the session, saving all undeleted, unsaved
messages in the user's mbox file in his or her login
directory, preserving all messages marked with hold or
preserve or never referenced in the user's system mailbox,
and removing all other messages from the user's system mailbox. If
new mail has arrived during the session, the message "You have new
mail" is given. If you quit while editing a mailbox file
with the -f flag, mailx(1) rewrites file you are
editing, and returns you to the shell, unless the file rewrite
fails. If it fails, you can escape mailx(1) with the
exit command.
reply
(r) Reply to a message (or message list); the reply is
sent to the sender and all recipients of one or more specified
messages. The default message must not be deleted.
respond
A synonym for reply.
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 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
(s) Append each message in a message list to the end of
a specified file. The mailx(1) utility echoes to the
terminal the file name, the line count, and the character
count.
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 can be placed around any part of the assignment
statement to quote blanks or tabs; that is,
set indentprefix=->
saveignore
The saveignore command is to save as
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.
saveretain
The saveretain command is to save as
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. The
saveretain command overrides saveignore.
shell
(sh) Invokes an interactive version of the shell.
size
Takes a message list and prints out the size in characters of
each message.
source
The source command reads commands from a file.
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.
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
(U) Takes a message list and marks each message as
not having been read.
unset
Takes a list of option names and discards their remembered
values; the inverse of set.
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
The mailx(1) utility presents message headers in
windowfuls as described under the headers command. You can
move forward to the next window with the z command. Also,
you can move back to the previous window by using z-.
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
something of a misnomer because the actual escape character can be
set by the option escape.
~!command
Execute the indicated shell command, then return to the
message.
~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 can continue appending text to
the message.
~fmessages
Read the named messages into the message being sent. If no
messages are specified, read in the current message. Message
headers currently being ignored (by the ignore or
retain command) are not included.
~Fmessages
Identical to ~f, except all message headers are
included.
~h
Edit the message header fields by typing each one in turn and
allowing the user to append text to the end or modify the field by
using the current terminal-erase and kill characters.
~mmessages
Read the named messages into the message being sent, indented
by a tab or by the value of indentprefix. If no messages are
specified, read the current message. Message headers currently
being ignored (by the ignore or retain commands) 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.
~rfilename
Read the named file 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 alternate editor (defined by the VISUAL
option) on the message collected so far. Usually, the alternate
editor will be a screen editor. After you quit the editor, you can
resume appending text to the end of your message.
~wfilename
Write the message onto the named file.
~|command
Pipe the message 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, you should
double that character to send it.
Options are controlled with set and unset
commands. Options can be either binary or string. If they are
binary, it is only significant to determine whether they are set or
not. If they are string, 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 or /etc/mailx.rc).
ask
Causes mailx(1) to prompt you for the subject of each
message you send (unless a message has been specified with
-s). If you respond with simply a newline, no subject field
will be sent. This is synonymous with asksub.
askbcc
Causes mailx(1) to prompt you for the blind copy
list.
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.
asksub
Causes mailx(1) to prompt you for the subject of each
message you send (unless a message has been specified with
-s). If you respond with simply a newline, no subject field
will be sent. This is synonymous with ask.
autoprint
Causes the delete command to behave like dp;
thus, after deleting a message, the next one will be typed
automatically.
bang
Causes mailx(1) to treat specially exclamation marks in
escape command lines. (See the escape command.) The default
is off.
cmd=command
Sets a command as the default command invoked by the
pipe command.
debug
Setting the binary option debug is the same as
specifying -d on the command line and causes mailx(1)
to output various information useful for debugging
mailx(1).
dot
The binary option dot causes mailx(1) to
interpret a period alone on a line as the terminator of a message
you are sending.
flipr
Reverses the meaning of the R and r
commands.
header
Causes mailx(1) to display a header summary when entered
in read mode. The default is header.
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 @ characters.
ignoreeof
An option related to dot is ignoreeof that makes
mailx(1) refuse to accept a CONTROL+D as the end of a
message. The ignoreeof option also applies to
mailx(1) command mode.
keep
Causes mailx(1) to truncate an empty mailbox, system
mailbox, or mbox to zero length instead of removing it.
keepsave
Keep messages in the system mailbox even if they have already
been saved in other files. The default is nokeepsave.
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.
noheader
Setting the option noheader is the same as giving the
-N flag on the command line.
nosave
Usually, when you abort a message with two RUBOUT characters
(erase or delete), mailx(1) copies the partial letter to the
file dead.letter in your home directory. Setting the binary
option nosave prevents this.
oneintr
Abort letter on one interrupt instead of two. See also the
ignore option and the -i option.
outfolder
Causes mailx(1) to store the files of outgoing messages
in the relative directory specified by the folder variable.
This has no effect if the value of folder is an absolute
path name.
page
Inserts a form-feed after each message sent through the pipe
created by the pipe command.
prompt=string
Sets the command-mode prompt to string. The default is
"? ". If the string is null, or noprompt is set,
mailx(1) does not prompt.
quiet
Suppresses the printing of the version when first invoked.
record=file
Records all outgoing mail in file; the default is
norecord. If outfolder is set, file is treated
as a directory that will contain files with outgoing mail.
replacedeadletter
If set, the existing dead-letter file is replaced by the
cancelled mail rather than appending the cancelled mail to the
existing dead-letter file.
Replyall
Reverses the sense of reply and Reply
commands.
save
Forces mailx(1) to save messages in the dead-letter file
(specified by DEAD) if they are interrupted or there are
delivery errors.
savelocal
If set, mailx(1) tries to save the dead-letter file in
the current directory instead of in the home directory.
screen=number
Sets the number of lines in a screenful of headers. This value
is used by the headers and z commands in mail-reading
mode. If not set, mailx(1) determines the current window
size.
searchheaders
If this option is set, 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.
sendmail=command
Specifies that command be used as the command for
delivering mail messages. For local delivery (useful for automatic
mail generated by utilities such as at(1)), set this value
to /bin/ssimda. (It is automatically prefixed with the value
of INTERIX_ROOT.) For external delivery, a package including
sendmail(1) will be available in the future.
show-rcpt
Specifies that the recipient, not the sender, is displayed in
header summaries.
showto
When displaying a header summary, displays the recipient
instead of the sender for any messages that you sent.
Sign
Contains a string that is inserted into the message when you
give the ~A command.
sign
Contains a string that is inserted into the message when you
give the ~a command.
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.
Path name of the text editor to use in the edit command
and ~e escape. If not defined, a default editor is
used.
LISTER
Path name of the directory lister to use in the folders
command. Default is /bin/ls.
PAGER
Path name of the program to use in the more command or
when the crt variable is set. If this option is not defined,
more(1) is used.
SHELL
Path name of the shell to use in the ! command and the
~! escape. A default shell is used if this option is not
defined.
VISUAL
Path name of the text editor to use in the visual
command and ~v escape.
crt
The valued option crt is used as a threshold to
determine how long a message must be before pager is used to
read it. If crt is set without a value, then the height of
the terminal screen stored in the system is used to compute the
threshold (see stty(1)).
escape=c
If defined, the character c is used in place of the
tilde character (~) to denote escapes.
folder
The name of the directory to use for storing folders of
messages. If this name begins with a forward slash (/),
mailx(1) considers it to be an absolute path name;
otherwise, the folder directory is found relative to your home
directory.
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.
record
If defined, gives the path name of the file used to record all
outgoing mail. If not defined, outgoing mail is not so saved.
indentprefix
String used by the ~m tilde escape in place of the
default tab character (^I) for indenting messages. Be sure
to quote the value if it contains spaces or tabs.
toplines
The number of lines to be printed with the top command;
usually, the first five lines are printed.
The mailx(1) utility uses the following environment
variables:
DEAD
The name of the file in which to save interrupted or cancelled
mail. The default is $HOME/dead.letter.
EDITOR
The editor to use when the edit or ~e commands
are given.Default is vi(1).
HOME
The user's home directory.
LISTER
The command used for listing the contents of the folder
directory when the folders command is given. Defaults to
ls(1).
MAILRC
The personal startup file to use. Defaults to
$HOME/.mailrc.
MBOX
The file used to save read messages. Defaults to
$HOME/mbox.
PAGER
The command used to display a mail message if the number of
lines in the message is greater than the value of the crt
variable.
SHELL
The command interpreter to use for the ! command.
Defaults to sh(1).
TERM
The name of the terminal type. If the variable screen
has not been set, mailx(1) uses the description of the
terminal to determine the number of lines on the screen.
VISUAL
The name of the editor to use when the visual or
~v commands are given. Defaults to vi(1).
The post office; new mail is delivered to this directory.
~/mbox
User's old mail.
$HOME/.mailrc
Personal startup file. Commands in this file are executed after
commands in /etc/mail.rc and /etc/mailx.rc.
/tmp/R*
Temporary files.
/usr/share/misc/Mail.*help
Help files.
/etc/mail.rc
System initialization file. This file is also read if
mailx(1) is invoked as mail(1).
/etc/mailx.rc
System initialization file. This file is only read if
mailx(1) is invoked as mailx(1). Commands in this
file supersede those in /etc/mail.rc, but may be superseded
by those in the user's personal startup file,
$HOME/.mailrc.