Jump to content United States-English
HP.com Home Products and Services Support and Drivers Solutions How to Buy
» Contact HP
More options
HP.com home
HP-UX Reference > M

mailx(1)

HP-UX 11i Version 3: February 2007
» 

Technical documentation

» Feedback
Content starts here

 » Table of Contents

 » Index

NAME

mailx — interactive mail message processing system

SYNOPSIS

Send mode

mailx [-FUm] [-s subject] [-r address] [-h number] address ...

Receive mode

mailx -e

mailx [-UHLiNn] [-u user]

mailx -f [-UHLiNn] [filename]

Obsolescent

mailx [-f filename] [-UHLiNn]

DESCRIPTION

mailx provides a comfortable, flexible environment for sending and receiving messages electronically. When reading mail, mailx provides commands to facilitate saving, deleting, and responding to messages. When sending mail, mailx allows editing, reviewing and other modification of the message as it is created.

Incoming mail for each user is stored in a standard file called the system mailbox for that user. When using mailx to read messages, the system mailbox is used unless an alternate mailbox file is specified by using the -f option with or without a specific filename. As incoming messages are read from the system mailbox, they are marked to be moved to a secondary file for storage (unless specific action is taken) so that the messages need not be seen again. This secondary file is called the mbox and is usually located in the user's HOME directory (see MBOX in the Environment Variables subsection for a description of this file and other environment variables used by mailx). Messages remain in this file until specifically removed.

Command-line options start with a hyphen (-), and any other arguments are assumed to be destinations (recipients).

Arguments containing multiple words must be enclosed in quotes.

If no recipients are specified, mailx attempts to read messages from the system mailbox.

Recipient addresses specified on the command line must total less than 1024 characters in length. You may declare an alias or group (see the COMMANDS section) to specify a recipient address or list of addresses of up to 8191 characters, and use that alias or group name (though each address in the list must still be less than 1024 characters). If you wish to specify a list of recipient addresses of greater length than this, have your system administrator declare an alias or group in the system alias file /etc/mail/aliases and use that alias name instead.

Options

mailx recognizes the following command-line options:

-e

Test for presence of mail. mailx prints nothing and exits with a successful return code if there is mail to read. Sometimes used in login scripts such as $HOME/.profile to check for mail during login.

-f filename

Read messages from filename instead of from the user's system mailbox. If filename is not specified, the secondary mbox is used.

.CR

Note: When using the -f filename option in mailx, do not specify a system mailbox (for example, /var/mail/user) as the filename. According to the mailx standards, the -f option cannot be used to read the system mailbox messages. The behavior of mailx in this circumstance is undefined.

.CR

The behavior of mailx is also undefined in these circumstances:

  • When the -f and -u options are used together in the command line.

  • When the -f or -u option is used multiple times in the command line.

-F

Record the message in a file named after the first recipient. Overrides the record environment variable, if set.

-h number

The number of network "hops" made so far. This is provided for network software to prevent infinite delivery loops.

-H

Print header summary only.

-L

Print complete header information only.

-i

Ignore interrupts. Also see the description of the ignore environment below.

-n

Do not initialize from the system default mailx.rc file.

-m

Do not add MIME header lines Mime Version, Content Type & Content Encoding to the header information while sending mails.

-N

Do not print initial header summary.

-r address

Pass address to network delivery software. All tilde commands are disabled.

-s subject

Set the Subject header field to subject.

-u user

Read user's mailbox. Can be used only if read access to user's mailbox is not read protected.

-U

Convert UUCP-style addresses to Internet standards. Overrides the conv environment variable.

-d

Turn on debugging output. Neither particularly interesting nor recommended.

When reading mail, mailx operates in command mode. A header summary of the first several messages is displayed, followed by a prompt indicating that mailx can accept regular commands (see the COMMANDS section). When sending mail, mailx operates in input mode. If no subject is specified on the command line, a prompt for the subject is printed. As the message is typed, mailx reads the message and stores it in a temporary file. Commands can be entered by beginning a line with the tilde (~) escape character followed by a single command letter and optional arguments. See the TILDE ESCAPES section for a summary of these commands.

The behavior of mailx at any given time is governed by a set of environment variables; flags and valued parameters that are set and cleared by using the set and unset commands. See the Environment Variables subsection for a summary of these parameters.

Recipients listed on the command line can be of three types: login names, shell commands, or alias groups. Login names can be any network address, including mixed network addressing. If the recipient name begins with a pipe symbol (|), the rest of the name is assumed to be a shell command to pipe the message through. This provides an automatic interface with any program that reads the standard input, such as lp (see lp(1)) for recording outgoing mail on paper. Alias groups are set by the alias command (see the COMMANDS section) and are lists of recipients of any type.

Note: To send a message to an alias name that is prefixed with a plus (+) symbol, the alias name with the plus (+) symbol must be placed within double quotes ("), as specified below:

  • mailx [-s subject] \"+alias\"

If the double quotes are not used, mailx considers the alias name as a user-specified file name beginning with a plus symbol, similar to the folder=directory option under EXTERNAL INFLUENCES.

Regular mailx commands are of the form

[command] [msglist ] [ arguments ]

If no command is specified in command mode, print is assumed. In input mode, commands are recognized by the escape character (tilde unless redefined by the escape environment variable), and lines not treated as commands are treated as input for the message.

Each message is assigned a sequential number, and there is always the notion of a current message, marked by a > in the header summary. Many commands take an optional list of messages (msglist) to operate on, which defaults to the current message. A msglist is a list of message specifications separated by spaces. The message list can include:

n

Message number n.

.

The current message.

^

The first undeleted message.

$

The last message.

*

All messages.

n-m

An inclusive range of message numbers, n through m, where n is less than m.

user

All messages from user.

/string

All messages with string in the subject line (uppercase-lowercase differences are ignored).

:c

All messages of type c, where c is one of:

d

deleted messages

n

new messages

o

old messages

r

read messages

u

unread messages

Note that the context of the command determines whether this type of message specification makes sense.

Other arguments are usually arbitrary strings whose usage depends on the command involved.

File names, where expected, are expanded using normal shell conventions (see sh(1)). Special characters are recognized by certain commands, and are documented with the commands below.

At start-up time, mailx reads commands from a system-wide file (/usr/share/lib/mailx.rc) to initialize certain parameters, then from a private start-up file ($HOME/.mailrc) for personalized variables. Most regular commands are legal inside start-up files, the most common use being to set up initial display options and alias lists. The following commands are not legal in the start-up file: !, Copy, edit, followup, Followup, hold, mail, preserve, reply, Reply, shell, and visual. Any errors in the start-up file cause the remaining lines in the file to be ignored.

COMMANDS

The following is a complete list of mailx commands:

! command

Escape to the shell. See the description of the SHELL environment variable below.

# comment

Null command (comment). Useful in .mailrc files.

=

Print the current message number.

?

Print a summary of commands.

newline

Advance to next message and print. If this is the first command entered, the first unread message is printed. (To read the current message, use print.)

alias alias name...

group alias name...

Declare an alias for the given names. The names are substituted when alias is used as a recipient. Useful in the .mailrc file.

alternates name...

Declares a list of alternate names for your login. When responding to a message, these names are removed from the list of recipients for the response. With no arguments, alternates prints the current list of alternate names. See also allnet in the Environment Variables subsection.

cd [directory]

chdir [directory]

Change directory. If directory is not specified, $HOME is used.

copy [filename]

copy [msglist] filename

Copy messages to the file without marking the messages as saved. Otherwise equivalent to the save command.

Copy [msglist]

Save the specified messages in a file whose name is derived from the author of the message to be saved, without marking the messages as saved. Otherwise equivalent to the Save command.

delete [msglist]

Delete messages from the mailbox. If autoprint is set, the next message after the last one deleted is printed (see the Environment Variables subsection). See also dp.

discard [header-field ...]

ignore [header-field ...]

Suppresses printing of the specified header fields when displaying messages on the screen. Examples of header fields to ignore are "status" and "cc." 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 next message after the last one deleted. Roughly equivalent to a delete command followed by a print command.

echo string ...

Echo the given string or strings (similar to echo - see echo(1)).

edit [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 (see the Environment Variables subsection). Default editor is ed (see ed(1)).

exit

xit

Exit from mailx, without changing the mailbox. No messages are saved in the mbox (see also quit).

file [filename]

folder [filename]

Quit from the current file of messages and read in the specified file. Several special characters are recognized when used as file names, and substitutions are made as follows:

%

the current mailbox.

%user

the mailbox for user.

#

the previous file.

&

the current mbox.

Default file is the current mailbox.

folders

Print the names of the files in the directory set by the folder variable (see the Environment Variables subsection).

followup [message]

Respond to a message and record the response in a file whose name is derived from the author of the message. Overrides the record variable, if set. See also the Followup, Save, and Copy commands and outfolder (see the Environment Variable subsection).

Followup [msglist]

Respond to the first message in the msglist, sending the message to the author of each message in the msglist. The subject line is extracted 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 followup, Save, and Copy commands and outfolder (see the Environment Variables subsection).

from [msglist]

Print the header summary for the specified messages.

group alias name...

alias alias name...

Declare an alias for the given names. The names are substituted when alias is used as a recipient. Useful in the .mailrc file.

headers [message]

Prints the page of headers which includes the message specified. The screen variable sets the number of headers per page (see the Environment Variables subsection). See also the z command.

help

Prints a summary of commands.

hold [msglist]

preserve [msglist]

Holds the specified messages in the mailbox.

if s|r

mail-commands

else

mail-commands

endif

Conditional execution, where s executes the accompanying mail-commands, up to an else or endif if the program is in send mode, and r causes the accompanying mail-commands to be executed only in receive mode. Intended for use in .mailrc files.

ignore header-field ...

discard header-field ...

Suppresses printing of the specified header fields when displaying messages on the screen. Examples of header fields to ignore are status and cc. All fields are included when the message is saved. The Print and Type commands override this command.

list

Prints all commands available. No explanation is given.

mail name ...

Mail a message to the specified users.

mbox [msglist]

Arrange for the given messages to end up in the standard mbox save file when mailx terminates normally. See MBOX in the Environment Variables subsection for a description of this file. See also the exit and quit commands.

next [message]

Go to next message matching message. A msglist can be specified, but in this case the first valid message in the list is the only one used. This is useful for jumping to the next message from a specific user since the name would be interpreted as a command in the absence of a real command. See the discussion of msglists above for a description of possible message specifications.

pipe [msglist] [command]

| [msglist] [command]

Pipe messages in msglist through the specified command. Each message is treated as if it were read. If msglist is not specified, the current message is used. If command is not specified, the command specified by the current value of the cmd variable is used. If msglist is specified, command must also be specified. If the page variable is set, a form feed character is inserted after each message (see the Environment Variables subsection).

preserve [msglist]

hold [msglist]

Preserve the specified messages in the mailbox.

Print [msglist]

Type [msglist]

Print the specified messages on the screen, including all header fields. Overrides suppression of fields by the ignore command.

print [msglist]

type [msglist]

Print the specified messages. If crt is set, messages longer than the number of lines specified by the crt variable are paged through the command specified by the PAGER variable. The default command is pg (see pg(1)), but many users prefer more (see more(1); see the Environment Variables subsection).

quit

Exit from mailx, storing messages that were read in mbox and unread messages in the user's system mailbox. Messages that have been explicitly saved in a file are deleted.

Reply [msglist]

Respond [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 file name, the response is saved at the end of that file (see the Environment Variables subsection).

reply [message]

respond [message]

Reply to the specified message, including all other recipients of the message. If record is set to a file name, the response is saved at the end of that file (see the Environment Variables subsection).

Save [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 based on the author's name with all network addressing stripped off. See also the Copy, followup, and Followup commands and outfolder (see the Environment Variables subsection).

save [filename]

save [msglist] filename

Save the specified messages in the given file, filename. The file is created if it does not exist. The message is deleted from the mailbox when mailx terminates unless keepsave is set (see the Environment Variables subsection and the exit and quit commands).

Note: If mailx is invoked with the -f option, the save command performs the same function as the copy command.

set

set name

set name=string

set name=number

Define a variable called name. The variable can be given a null, string, or numeric value. Set by itself prints all defined variables and their values (see the Environment Variables subsection for detailed descriptions of the mailx variables).

shell

Invoke an interactive shell (see SHELL in the Environment Variables subsection).

size [msglist]

Print the size in characters of the specified messages.

source filename

Read commands from the given file and return to command mode.

top [msglist]

Print the top few lines of the specified messages. If the toplines variable is set, it is interpreted as the number of lines to print (see the Environment Variables subsection). The default is 5.

touch [msglist]

Touch the specified messages. If any message in msglist is not specifically saved in a file, it is placed in the mbox upon normal termination. See exit and quit.

Type [msglist]

Print [msglist]

Print the specified messages on the screen, including all header fields. Overrides suppression of fields by the ignore command.

type [msglist]

print [msglist]

Print the specified messages. If crt is set, messages longer than the number of lines specified by the crt variable are paged through the command specified by the PAGER variable. The default command is pg but many users prefer more (see the Environment Variables subsection).

unalias alias

Discard the specified alias names.

undelete [msglist]

Restore the specified deleted messages. Restores only messages that were deleted in the current mail session. If autoprint is set, the last message of those restored is printed (see the Environment Variables subsection ).

unset name...

Cause the specified variables to be erased. If the variable was a shell variable imported from the execution environment, it cannot be erased.

version

Prints the current version and release date.

visual [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 (see the Environment Variables subsection).

write [msglist] filename

Write the given messages on the specified file, except for the header (the "From ..." line) and trailing blank line. Otherwise equivalent to the save command.

xit

exit

Exit from mailx, without changing the mailbox. No messages are saved in the mbox (see also quit).

z[+|-]

Scroll the header display forward or backward one screen-full. The number of headers displayed is set by the screen variable (see the Environment Variables subsection).

TILDE ESCAPES

The following commands can be used only when in input mode, by beginning a line with the tilde escape character (~). See escape (in the Environment Variables subsection) for changing this special character.

~!command

Escape to the shell.

~.

Simulate end of file (terminate message input).

~:mail-command

~_ mail-command

Perform the command-level request. Valid only when sending a message while reading mail.

~?

Print a summary of tilde escapes.

~A

Insert the autograph string Sign into the message (see the Environment Variables subsection).

~a

Insert the autograph string sign into the message (see the Environment Variables subsection).

~b name ...

Add name to the blind carbon copy (Bcc) list.

~c name ...

Add name to the carbon copy (Cc) list.

~d

Read in the dead.letter file. See DEAD (in the Environment Variables subsection) for a description of this file.

~e

Invoke the editor on the partial message. Also see the EDITOR environment variable description below.

~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, it can be edited as if you had just typed it.

~i string

Insert the value of the named variable into the text of the message. For example, ~A is equivalent to ~i Sign.

~m [msglist]

Insert the specified messages into the letter, shifting the new text to the right one tab stop. Valid only when sending a message while reading mail.

~p

Print the message being entered.

~q

Quit (terminate) input mode by simulating an interrupt. If the body of the message is not null, the partial message is saved in dead.letter. See the description of the DEAD environment variable below for a description of this file.

~R name ...

Add name to the Reply-To list.

~r filename

~< filename

~<!command

Read in the specified file. If the argument begins with an exclamation point (!), the rest of the string is assumed to be an arbitrary shell command and is executed, with the standard output inserted into the message.

~s string ...

Set the subject line to string.

~t name ...

Add the given names to the To list.

~v

Invoke a preferred screen editor on the partial message. Also see the VISUAL environment variable description below.

~w filename

Write the partial message onto the given file, without the header.

~x

Exit as with ~q except the message is not saved in dead.letter.

~| command

Pipe the body of the message through the given command. If command returns a successful exit status, the output of the command replaces the message.

EXTERNAL INFLUENCES

Environment Variables

The following variables are internal mailx program variables. They can be imported from the execution environment or set by the set command at any time. The unset command can be used to erase variables.

allnet

All network names whose login names match are treated as identical. This causes the msglist message specifications to behave similarly. Default is noallnet. See also the alternates command and the metoo variable.

append

Upon termination, append messages to the end of the mbox file instead of inserting them at the beginning of the file. Default is noappend.

askbcc

Prompt for the Bcc list after the message is entered. Default is noaskbcc.

askcc

Prompt for the Cc list after the message is entered. Default is noaskcc.

asksub

Prompt for a subject if it is not specified on the command line with the -s option. Enabled by default.

autoprint

Enable automatic printing of messages after delete and undelete commands. Default is noautoprint.

bang

Enable special-case treatment of exclamation points (!) in shell escape command lines as in vi. Default is nobang.

charset=charset

Set the default character set. If none is specified, mailx will attempt to use the value of LANG to look up the system default for the user's locale. If that is unsuccessful, the default value of us-ascii will be used.

cmd=command

Set the default command for the pipe command. No default value.

conv=conversion

Convert UUCP addresses to the specified address style. The only valid conversion currently supported is internet, which requires a mail delivery program conforming to the RFC822 standard for electronic mail addressing. Conversion is disabled by default. See also sendmail and the -U command-line option.

crt=number

Pipe messages having more than number lines through the command specified by the value of the PAGER variable pg by default (see pg(1)). Disabled by default.

DEAD=filename

The name of the file in which to save partial letters in case of untimely interrupt or delivery errors. Default is $HOME/dead.letter.

debug

Enable verbose diagnostics for debugging. Messages are not delivered. Default is nodebug.

dot

When processing input from a terminal, interpret an ASCII period character on a line by itself as end-of-file. Default is nodot.

EDITOR=command

The command to run when the edit or ~e command is used. Default is ed (see ed(1)).

encoding=encoding

Set the default encoding to be used when 8-bit characters are present. Allowable values are quoted-printable, base64 and 8bit. The short-hand q-p is also acceptable for quoted-printable. The default value will be determined based upon the value of charset. A value of 8bit means not to encode.

escape=c

Substitute c for the ~ escape character.

folder=directory

The directory for saving standard mail files. User specified file names beginning with a plus (+) are expanded by preceding the file name with this directory name to obtain the real file name. If directory does not start with a slash (/), $HOME is used as a prefix. There is no default for the folder variable. See also outfolder below.

header

Enable printing of the header summary when entering mailx. Enabled by default.

hold

Preserve all messages that are read in the system mailbox instead of putting them in the standard mbox save file. Default is nohold.

ignore

Ignore interrupts while entering messages. Useful when communicating over noisy dial-up lines. Default is noignore.

ignoreeof

Ignore end-of-file during message input. Input must be terminated by a period (.) on a line by itself or by the ~. command. Default is noignoreeof. See also dot above.

keep

When the mailbox is empty, truncate it to zero length instead of removing it. Disabled by default.

keepsave

Keep messages that have been saved in other files in the system mailbox instead of deleting them. Default is nokeepsave.

MBOX=filename

The name of the file to save messages which have been read. The xit command overrides this function, as does saving the message explicitly in another file. Default is $HOME/mbox.

metoo

Usually, when a group (alias) containing the sender is expanded, the sender is removed from the expansion. Setting this option causes the sender to be included in the group. Default is nometoo.

mimeheader=value

To add or disable MIME header when sending mail. value can be yes or no.

LISTER=command

The command (and options) to use when listing contents of the folder directory. The default is ls.

NOMETAMAIL=value

To disable the usage of metamail to read MIME messages, set the value to TRUE. By default the NOMETAMAIL variable is not set.

onehop

When responding to a message that was originally sent to several recipients, the other recipient addresses are normally forced to be relative to the originating author's machine for the response. This flag disables alteration of the recipients' addresses, improving efficiency in a network where all machines can send directly to all other machines (that is, one hop away).

outfolder

Cause the files used to record outgoing messages to be located in the directory specified by the folder variable. Default is nooutfolder. See folder above and the Save, Copy, followup, and Followup commands.

page

Used with the pipe command to insert a form feed after each message sent through the pipe. Default is nopage.

PAGER=command

The command to use as a filter for paginating output. This can also be used to specify the pager command-line options (for example, set PAGER="more -c" ). Default is pg, but many users prefer more (see pg(1) and more(1)).

prompt=string

Set the command-mode prompt to string. Default is ?.

quiet

Refrain from printing the opening message and version when entering mailx. Default is noquiet.

record=filename

Record all outgoing mail in filename. Disabled by default. See also outfolder above.

replyto=address

Specify address to which responses are to be sent.

save

Enable saving of messages in dead.letter on interrupt or delivery error. See DEAD for a description of this file. Enabled by default.

screen=number

Set the number of lines in a screen-full of headers for the headers command.

sendmail=command

Alternate command for delivering messages. Default is mail (see mail(1)).

sendwait

Wait for background mailer to finish before returning. Default is nosendwait.

SHELL=command

The name of a preferred command interpreter. Default is the user's login program (see passwd(4), shells(4), and chsh(1)). Note: in the unusual case that a user's login program is a script file from which mailx is executed, rather than a shell, then mailx requires that the user explicitly set SHELL=/usr/bin/sh in his or her $HOME/.mailrc file.

showto

When displaying the header summary and the message is from you, print the recipient's name instead of the author's name.

sign=string

The variable that is inserted into the text of a message when the ~a (autograph) command is given. No default (see also ~i in the TILDE ESCAPES section).

Sign=string

The variable inserted into the text of a message when the ~A command is given. No default (see also ~i in the TILDE ESCAPES section).

SMARTMAILER

When SMARTMAILER is set, various commands use the From: line instead of the default From line.

toplines=number

The number of lines of header to print with the top command. Default is 5.

VISUAL=command

The name of a preferred screen editor. Default is vi (see vi(1)).

The following are environment variables taken from the execution environment and are not alterable within mailx.

HOME

The user's home directory. This is usually the current directory immediately after login.

MAIL

The name of the initial mailbox file to be read. By default, the mailbox is set to /var/mail/username. This environment variable overrides the default setting and causes mailx to open the mailbox specified by the environment variable.

MAILRC

The name of the mailer start-up file. Default is $HOME/.mailrc.

LC_COLLATE

LC_CTYPE

LC_COLLATE and LC_CTYPE influence mailx when the command interpreter (see the SHELL environment variable) is invoked. To determine the behavior of LC_COLLATE and LC_CTYPE, see the corresponding shell manpage for the applicable command interpreter.

LC_TIME

LC_TIME determines the format and contents of the date and time strings displayed. If LC_TIME is not specified in the environment, or is set to the empty string, the value of LANG is used as a default. If LANG is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of LANG. If any internationalization variable contains an invalid setting, mailx behaves as if all internationalization variables are set to "C". See environ(5).

TMPDIR

When set, the TMPDIR environment variable specifies a directory to be used for temporary files, overriding the default directory /tmp.

International Code Set Support

Single- and multibyte character code sets are supported within mail text. Headers are restricted to characters from the 7-bit USASCII character code set (see ascii(5)).

WARNINGS

Where command is shown as valid, arguments are not always allowed. Experimentation is recommended.

Internal variables imported from the execution environment cannot be unset.

The full internet addressing is not fully supported by mailx. The new internationalization standards need some time to settle down.

mail, the standard mail delivery program, treats a line consisting solely of a dot (.) as the end of the message.

Using two separate mail programs to access the same mail file simultaneously (usually inadvertently from two separate windows) can cause unpredictable results.

Arguments containing multiple words must be enclosed in quotes. Otherwise they may be interpreted incorrectly.

FILES

/var/mail/

Post office directory (mode 775, group ID mail)

/var/mail/user

System mailbox for user (mode 660, owned by user, group ID mail)

$HOME/.mailrc

Personal start-up file

/usr/share/lib/mailx.rc

Global start-up file

$HOME/mbox

Secondary storage file

/tmp/R[emqsx]*

Temporary files

STANDARDS CONFORMANCE

mailx: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2

For more information about mailx, also refer to the mailx section in the UNIX 95 standard document specification.

Printable version
Privacy statement Using this site means you accept its terms Feedback to webmaster
© 1983-2007 Hewlett-Packard Development Company, L.P.