Previous Table of Contents Next

BSD (Berkeley)
-f [ filename ] Same as mailx -f option
-i Same as mailx -i option
-n Same as mailx -n option
-s subject Same as mailx -s option
-u user Same as mailx -u option
-v Sets verbose mode. Detailed delivery information is displayed.
Resembles mailx -d option.

The -h, -r, and -U options can be used only if mailx uses a mail delivery program other than the /bin/mail program.


The following list describes the arguments that may be passed to the mailx command.

recipients A list of recipients to whom the mail message is sent. A recipient may be one of three types:
user_name The name of a user on the local system or on a remote system. If the user is on a remote system, you must specify how the message is to be sent. The first is the uucp format of system!user. For example, sundal!mitek!rjf sends the mail to the system sundal, which forwards the mail to the system named mitek where the user rjf resides. The second is the internet format of user@system. The same address above is written as rjf@mitek.
shell_command A UNIX shell command that reads the standard input. The recipient name must begin with a | (pipe). The command must be in quotes. For example,
                                       mailx rjf "|lp"
sends the message to the user rjf and to the default printer.
alias_group An alias_group allows you to define a group of users. You then specify the group name and the message is sent to each user in the group. For example, in your .mailrc file you might specify
                                       alias doc "aba barb ccb jag"
so when you specify doc as a recipient all of the users in the "doc" alias_group are sent the message.


Since mailx can be customized to each user's preferences, we discuss the default behavior of mailx in this section. You can customize mailx by using shell and internal variables.

Sending Mail

When you want to send mail to other users, run mailx followed by a list of users. A header is added to the message you are sending. The header identifies you (the sender), the date of creation, and a subject line. The message is then sent to each user's mailbox in the /usr/mail (/usr/spool/mail on BSD) directory. The mailbox is a file named after the user's login or user name. For example, the user tlp has a mailbox named /usr/mail/tlp.

Reading Mail

When you want to read your mail, run mailx without a list of users. mailx checks your mailbox for mail. If you have messages in your mailbox, mailx displays a header line for each message. You can then perform different commands to manipulate the message list and messages. If you read (or touch) a message, it is saved to the file mbox when you exit mailx. The mbox file contains messages you have received and did not delete or save in a different file. Your mailbox (/usr/mail/mylogin) contains all new messages that have not been read.

The mailx command is compatible with the older mail command and thus uses the same mailbox. The older mail program does not include a header for each message, nor the vast array of commands to handle messages.


To send mail you simply specify the users you want to send messages as arguments to mailx. For example,

     mailx bill jill phil

sends the message you enter to the users, bill, jill, and phil. When you specify user names on the command line, mailx knows you want to send a message to recipients. After you press Return on the command line mailx prompts you for a subject line. You can press Return to have mailx ignore the subject line or you can enter a line of text. For example,

     mailx barb
     Subject: About the database problem!

Only the first 40 characters of the subject line are displayed when the user displays the header information using the h command.

After you enter the Subject line, mailx enters a simple editor or input mode. You enter your message text line-by-line pressing Return at the end of each line. You can use the Backspace key to erase characters on the current line but you cannot return to previous lines. To end the message you press Ctrl-D at the beginning of a line.

You can use the tilde escape commands to perform special functions while in input mode. One of the tilde commands allows you to enter the editor of your choice to edit the message. So even though mailx does not provide a true editor, it does allow you to invoke one to edit your message. For example,

     mailx barb
     Subject: About the database problem!

causes mailx to enter the visual editor for you to edit your message.

The mailx header and tilde escape commands are discussed in the next two sections.


When you send a message using mailx a header is added to the message. The header contains information much like the header of a standard office memorandum. The header has a Date, From, To, and Subject field. The Date field is automatically set when you invoke mailx. It has the same format as the default format returned by the date command. The From field is your user_name and your name taken from the /etc/passwd file. The To field contains the names of all users you want to send the message. And the Subject field contains a brief line informing the recipients what the message is about.

This line and all other message header lines are displayed on the recipient's screen when mailx is first invoked. The header lines can be displayed at any time from the command mode by using the header command. There are environment variables and tilde escape commands you can use to control which parts of the header are displayed.

The mailx command also provides an additional field for Carbon Copy control. The Cc field can be used by setting the askcc variable or by using the ~c or ~h tilde escape command. This field is a list of users who are to receive the message. The list of users is displayed in the header so all users know who received the message. A similar field is the Bcc (blind carbon copy) field. It works the same as the Cc field except the list of users receiving a copy are not listed in the header. So other recipients are not informed of who received the message.

Header Fields

The header is composed of several different fields. These fields are:

Field Description

Status The status of the message:
D - deleted message
N - new message
O - old message
R - read message
U - unread message
> - marks the current message
Date The date the message was mailed
From The user who sent the message
To The user(s) to whom the message is sent
Subject The subject to which the message relates
Cc The users to whom carbon copies of the message is sent
Bcc The users to whom blind carbon copies of the message is sent. Other users are not notified about who received a blind carbon copy.


The tilde escape commands allow you to edit and modify the message you are sending to the specified users. They can only be used while you are in insert mode. You can enter insert mode two ways. The first is by entering the mailx command from the shell, followed by user names. Another way to enter the input mode is from the command mode of mailx. The mail or reply commands place you in input mode.

When you are in input mode you can request special tilde escape commands by entering a tilde (~) followed by a command at the beginning of an input line. For example, ~v followed by Return, places you in the vi editor, thus allowing you to edit your message with vi.

You can change the escape character from tilde (~) to some other character by using the escape variable in mailx.

Previous Table of Contents Next