Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

mailx - interactive message processing system (mail extended)

&pagelevel(4)&pagelevel

This description is divided into the following sections:

Introduction

mailx enables you to send and receive electronic mail. If MAIL of the interNet Services (formerly interNet Value Edition) ist installed you can exchange messages with other users on the same system.

The presence of mail, if any, is usually indicated when you log in. You are also notified if new mail arrives while you are using mailx.

Messages have a message header holding information needed for message forwarding.

The message header contains the following fields:


MessageNumber of the message

FromSender of the message, date and time

ToRecipient of the message

SubjectTitle of the message (see option -s)

Status

Processing status of the message (see description on "mailx interactive message processing system (mail extended)")

The header is followed by a blank line and then the text of the message.

The mailx utility allows you to:

  • check for the presence of mail (read mode, Format 1, option -e)

  • read messages (read mode, Format 1)

  • use shell commands to process incoming messages (read mode, Format1, mailx commands !, | and pipe)

  • send messages (send mode, Format 2)

  • use an editor to edit messages during a mailx session (read and send mode, mailx commands edit, visual, ̃e and ̃v).

mailx automatically collects read messages in a user-specific mailbox ($HOME/mbox by default).


Syntax

Synopsis of mailx formats


Format 1: mailx[ option]
Format 2: mailx[ option]... recipient...


Read mode


Format 1: mailx[ option]


No option specified

mailx behaves as described in Functionality in read mode.

-e

mailx simply checks whether there are any messages, terminating with an exit status of 0 if the user has mail. Otherwise, an exit status of 1 is returned.
mailx does not execute any startup files (see “mailx command and startup files”).

-f[ file]

mailx reads messages from file.

file not specified:
mailx reads messages from the user-specific mailbox $HOME/mbox.

-f file not specified:
mailx reads messages from the default mailbox /var/mail/$USER.

-H

(H - Header)

mailx displays only the header summaries and terminates. The exit status is 0 if the user has mail, otherwise 1.

The structure of a header summary is described in Functionality in read mode).

-i

(i - ignore)

mailx ignores the signal SIGINT (see the mailx variable ignore on "mailx interactive message processing system (mail extended)").

-n

mailx does not initialize from the global startup file /etc/mail/mailx.rc (see “mailx command and startup files”).

-N

mailx does not print the initial header summary.

-u login_name

mailx reads messages from the default mailbox of the specified user, provided you have
the required read permission.

-V

mailx displays its version number and exits.


mailx commands in read mode

Input format

mailx commands in read mode have the following format:

[command][ msglist][ argument]...

command

Name of a mailx command. Most command names can be abbreviated. In “Descriptions in alphabetical order” the accepted abbreviations are shown in bold print.

command not specified:
If you simply pressthe enter key at the mailx prompt, mailx executes the print command.

msglist

One or more messages to be processed by the command. If several messages are specified, they are separated by blanks.

msglist can be one or more of the following:


n

Message number n

.

The current message (marked > in the header summary)).

^

The first undeleted message.

$

The last message.

*

All messages.

+

The next message.

-

The preceding message.

n-m

Messages n through m inclusive.

login_name

All messages from the specified user.

/str

All messages with the string str in the subject field (the case is ignored).

:msgtype

All messages of type msgtype, which can be any of the following:


d

deleted messages (useful only with the mailx command undelete)

n

new messages

o

old messages (any messages not in state new or read)

r

read messages

u

unread messages 


msglist not specified:
mailx defaults to the current message.

argument

String argument as appropriate to the command (see descriptions). If argument is a file name, the usual shell metanotation may be used. If a string containing blanks is to be interpreted as a single argument, it must be enclosed in double quotes.


Functional overview

This section provides an overview of all mailx read-mode commands, grouped by function. Some commands may appear more than once. The overview is followed by descriptions of all the commands in alphabetical order.
Most commands can be abbreviated. In “Descriptions in alphabetical order” the abbreviated forms are shown in bold print.


Help functions

?

Display summary of mailx commands

help

Display summary of mailx commands

list

List names of all mailx commands

=

Display current message number

size

Display size of message

from

Display header summary

z+

Scroll header display one page forward

z-

Scroll header display one page back

headers

Display screen page of headers

top

Display first five lines of message header

folders

List contents of directory defined by mailx variable folder

version

Display mailx version number


Quitting mailx

exit

Quit mailx without changing mailbox

xit

Quit mailx without changing mailbox

quit

Quit mailx


Displaying the header summary

from

Display header summary

headers

Display screen page of headers

z+

Scroll header display one page forward

z-

Scroll header display one page back


Manipulating and displaying the message header

discard

Suppress message header fields

undiscard

Undo the effect of discard

ignore

Suppress message header fields

unignore

Undo the effect of ignore

retain

Display only specified fields of message header

top

Display first five lines of message header


Displaying messages

print

Display message

type

Display message

next

Skip to next matching message

Print

Display message with full message header, ignoring discard

Type

Display message with full message header, ignoring discard


Editing messages

edit

Call editor to edit message (value of mailx variable EDITOR, default: ed)

visual

Call editor to edit message (value of mailx variable VISUAL, default: vi)


Changing the mailbox

file

Close current mailbox and open named one

folder

Close current mailbox and open named one


Saving messages

hold

Hold messages in mailbox

preserve

Hold messages in mailbox

save

Write message to file

copy

Write message to file

write

Write message to file, omitting header

mbox

Write message to user’s standard mailbox

touch

Write message to user’s standard mailbox

Save

Write messages to file named after sender of first message

Copy

Write messages to file named after sender of first message


Deleting messages

delete

Delete message

dp

Delete message, display next

dt

Delete message, display next


Switch to send mode and send or reply to message

mail

Send message

Mail

Send message, recording copy in file

reply

Reply to message

respond

Reply to message

followup

Reply to message, recording reply

Reply

Reply to list of messages

Respond

Reply to list of messages

Followup

Reply to list of messages, recording replies


Undoing mailx commands during a mailx session

undelete

Restore deleted messages

touch

Undo effect of hold

hold

Undo effect of touch

unalias

Erase aliases

undiscard

Undo effect of discard

unignore

Undo effect of ignore

unset

Erase variables


Invoking command interpreters, running shell commands

!

Escape to shell

!!

Repeat last shell command

shell

Invoke command interpreter

pipe

Pipe messages to standard input of shell command

|

Pipe messages to standard input of shell command


Miscellaneous

#

Null command (for including comments in command files)

=

Display current message number

alias

Declare aliases for mail recipients (same as group)

alternates

Declare alternate names for your login name

cd

Change directory

chdir

Change directory

echo

Echo string (like echo shell command)

folders

List contents of directory defined by mailx variable folder

group

Declare aliases for mail recipients (same as alias)

if mode cmdlist1 else cmdlist2 endif

construct which selects a command list to execute on the basis of the mode (send, read)

set

Set variables

size

Display size of message

source

Read and execute command file

unset

Erase variables


mailx commands not allowed in command files

!

Escape to shell

Copy

Write messages to file named after sender of first message

edit

Call editor to edit message

followup

Reply to message, recording reply

Followup

Reply to list of messages, recording replies

hold

Hold messages in mailbox

mail

Send message

Mail

Send message, recording copy in file


preserve


Hold messages in mailbox

reply

Reply to message

Reply

Reply to list of messages

respond

Reply to message

Respond

Reply to list of messages

shell

Invoke command interpreter

visual

Call editor to edit message

Descriptions in alphabetical order

Some command names have synonyms. The full description is always next to the name which comes first in alphabetical order.

Most of these commands can be used both interactively and in command files. Exceptions to this rule are mentioned at the appropriate place (see “Functional overview”).

The bold print in the command names refers to the abbreviated forms.


!shell_command

Executes shell_command. By default the command interpreter specified in the mailx variable SHELL will be invoked and the specified command line will be passed to it. If SHELL is not set, /bin/sh will be invoked.

If the bang variable is set, the last shell command executed is saved by mailx and can be repeated with !!.

The ! command is not permitted in a command file.

#comment

This is the null command used to introduce comments in command files (e.g. .mailrc).

=

Displays the current message number.

?

Displays a summary of all mailx commands.

alias[ alias-name[ recipient]]...
group[ alias-name[ recipient]]...

Declares an alias for the given recipients. The defined recipients are substituted when you use the aliases as recipients.

alias-name:
Any string.

alias-name not specified:
mailx displays a list of defined aliases.

recipient not specified: mailx displays the definitions for alias-name.

alternates[ name]...

Declares alternate names for your login name. Once you reply to a message, mailx deletes these alternative names from the list of recipients.

name:
String for the alternate name.

name not specified:
mailx displays the current list of alternate names.

cd [directory]
chdir [directory]

Changes to the indicated directory.

directory not specified:
mailx changes to $HOME.

copy[[ msglist] file]

Copies the specified messages to the named file. If file already exists, it is extended.The messages are marked as read (R) and copied to the user-specific mailbox when the default mailbox is closed.

No argument specified:
mailx appends the current message to $HOME/mbox.

If you do not subsequently delete the message, it will be saved again the next time the default mailbox is closed.

Copy[ msglist]

Copies the specified messages to a file in the current directory. The name of this file is derived from the name of the author of the first message in the message list (From entry).

If this file already exists, it is extended.

The messages are marked as read (R) and copied to the user-specific mailbox when the default mailbox is closed.

The Copy command is not permitted in a command file.

delete[ msglist]

Deletes the specified messages from the current mailbox. If the mailx variable autoprint is set, the message following the last deleted message is printed.

A deleted message can be restored with undelete during a mailx session.

discard[ field]...
ignore[ field]...

Suppresses printing of the specified header fields in the output if they appear at the start of a line and come before a colon, e.g.: Cc:, Date:, Status:, Subject:, To:. You do not need to include the colon, and mailx ignores the case of the letters in field.

discard has an effect on the mailx commands next, pipe (or |), print, type, ~f and ~m, but not on Print, Type, ~F  and ~M.

No fields are suppressed when messages are saved.

The effect of discard can be undone with undiscard or unignore. retain suppresses the effect of discard: all fields are ignored except those explicitly specified.

field not specified:
discard displays the current list of fields being ignored, if any.

dp[ msglist]
dt[ msglist]

(delete and print) Deletes messages from the mailbox and displays the message that follows the last one deleted.

A deleted message can be restored with undelete during a mailx session.

echo string ...

Echoes string on standard output (like the echo shell command).
The value of an environment variable can be accessed as $name. echo always displays the value of the environment variable, even if a mailx variable of the same name has been defined.

edit[ msglist]

Invokes the editor specified with the mailx variable EDITOR (default editor: ed) and loads the specified messages.

The edited message will be available in the mailbox again at the end of the editing session.

The text is edited in a temporary file named /tmp/Rz$$, where $$ is the process ID of the mailx process (see Files).

The edit command is not permitted in a command file.

exit
xit

Exits from mailx without changing the current mailbox, i.e.

  • deleted messages are restored,

  • read messages are not saved in $HOME/mbox, and

  • edited messages retain their original status.

Also refer to the mailx command quit.

file[ file]
folder[ file]

Quits the current mailbox (like quit) and reads in the specified file as another mailbox. The appropriate header lines are displayed.

file

Name of the mailbox to be processed, or the following metanotation:

%

the current mailbox

%login_name

the default mailbox of the named user (/var/mail/$USER)

+file

the file file in the directory folder (see mailx variable folder)

#

the previous mailbox

&

the user-specific mailbox ($HOME/mbox or the mailbox defined by the mailx variable $MBOX)

file not specified:
mailx remains in the current mailbox and simply reports the number of messages in it.

file % closes and reopens the current mailbox. This allows you to read any new messages that have arrived during your mailx session.

folders

Lists the names of all files in the directory defined by the mailx variable folder (messages are saved and recorded in this directory by mailx).

followup[ message]

Replies to the specified message like the mailx command reply.

mailx switches to send mode and considers the recipients to be

  • the author of the specified message, i.e. the entry in the "From" field is taken over to the "To" field,

  • the other recipients of the message, i.e. the entries in the "To" field are transferred to the "To" list, while those in the Cc field are copied to the Cc list.

When you have completed your input, mailx sends the message.

In contrast to reply, followup records the message in a file named after the recipient (with the network path removed). The storage location of this file depends on whether the mailx variables folder and outfolder are set. If both are set, the file is stored in the directory defined by the folder variable. Otherwise it is stored in the current directory. The file is extended if it already exists.

The followup command is not permitted in a command file.

Followup[ msglist]

Replies to the first of the messages specified in the message list in the same way as the mailx command Reply.

mailx switches to send mode and sends the reply to each sender of a message in msglist.

When you have completed your input, mailx sends the message.

In contrast to reply, Followup records the message in a file named after the sender of the first message (with the network path removed). The storage location of this file depends on whether the mailx variables folder and outfolder are set. If both are set, the file is stored in the directory defined by the folder variable. Otherwise it is stored in the current directory. The file is extended if it already exists.

The Followup command is not permitted in a command file.

from[ msglist]

Prints the header summary for all specified messages on the standard output.

group alias-name recipient...

Declares aliases for the given recipients (see alias).

headers[ message]

Displays the screen page of headers which includes the specified message. A screen page contains 20 lines or the number of lines defined by the screen variable.

message not specified:
mailx displays the current message.

help

Displays a summary of the mailx commands (see also ?).

hold[ msglist]
preserve[ msglist]

Holds (i.e. preserves) the specified messages in the default mailbox.

The messages are marked H in the header and remain in the mailbox, even if they have been read or saved.

The effect of hold can be undone with touch (and vice versa).

The hold and preserve commands are not permitted in a command file.

if mode
command_list1
else
command_list2
endif

if construct which selects a command list to execute on the basis of the specified mode.

mode

mode is the mode (send or read) in which you invoked mailx. It can be:

s

(send)

command_list1 is executed if you invoked mailx in send mode; otherwise, command_list2 is executed.

r

(read)

command_list1 is executed if you invoked mailx in read mode; otherwise, command_list2 is executed.

command_list1command_list2

Lists of mailx commands. Commands which are not permitted in command files are also not permitted here, i.e.: !, edit, followup, Followup, mail, Mail, reply, Reply, respond, Respond, shell and visual.

if, else, endif and all the commands in the command lists must each be on a separate line.

ignore[ field]...

Suppresses printing of the specified header fields (see discard on "mailx interactive message processing system (mail extended)").

list

Lists the names of all available mailx commands on standard output (also refer to help and ?).

mail recipient...

Sends a message to recipient.

mailx switches to send mode and mails the message as soon as you have finished entering the text.
If the mailx variable record is set, the message will be written to the file defined there. If the file already exists, it is extended.

The mail command is not permitted in a command file.

Mail recipient...

Sends a message to recipient.

mailx switches to send mode and mails the message as soon as you have finished entering the text.
mailx records your message in the current directory in a file named after the recipient. If the file already exists, it is extended.

The Mail command is not permitted in a command file.

mbox[ msglist]

Writes the listed messages to the user-specific mailbox when the current mailbox is closed and then deletes them from the current mailbox, even if they have not been read. All such messages are marked M in the header summary.

The user-specific mailbox is $HOME/mbox or the file defined by the mailx variable MBOX.

next[ message]

Goes to the next message containing message in the header summary. For message you can enter characteristics as for a message list.

If, for example, the next message you want to read is that of a particular sender, specify next sender.
The sender can be an e-mail address or a local user ID.

message not specified: mailx displays the message following the current one.

next otherwise works in the same way as print.

pipe[[ msglist] shell_command]
| [[ msglist] shell_command]

Pipes the specified messages to the standard input of the given shell_command.
The messages are marked as read (R) in the header summary. If the mailx variable page is set, a form feed character is inserted after each message (FF = CTRL+L = X’0C’).

No argument specified:
The default message is the current message, and the default command is the one specified by the mailx variable cmd. If cmd is not set, the pipe command is ignored.

preserve[ msglist]

Preserves the specified messages in the default mailbox (see hold).

print[ msglist]
type[ msglist]

Prints the specified messages on the standard output.

The messages are marked as read (R) in the header summary. They are copied to the user-specific mailbox upon termination of the default mailbox and then deleted from the current one. The user-specific mailbox is $HOME/mbox or the file defined by the mailx variable MBOX.
If the mailx variable crt is set, messages longer than the number of lines specified by the crt variable are paged through the POSIX command more. You can use the mailx variable PAGER to specify a POSIX command other than more.

Print[ msglist]
Type[ msglist]

Like print, except that the whole header is always displayed, i.e. Print overrides the effect of discard and ignore.

quit

Exits from mailx, closing the currently processed mailbox.
If the default mailbox was being processed, the following applies:

  • Read messages (0) and messages processed with mbox (M) are copied to the user-specific mailbox and then deleted. The user-specific mailbox is $HOME/mbox or the file defined by the mailx variable MBOX.

  • Unread messages (U) and messages processed with hold or preserve (P) are retained in the default mailbox.

  • Explicitly saved messages (S) are deleted from the mailbox, if the keepsave variable is not set.

Also refer to the mailx commands exit and xit.

reply[ message]
respond[ message]

Replies to the indicated message.

mailx switches to send mode and considers the recipients to be

  • the author of the specified message, i.e. the entry in the "From" field is taken over to the "To" field,

  • the other recipients of the message, i.e. the entries in the "To" field are transferred to the "To" list, while those in the Cc field are copied to the Cc list.

When you have completed your input, mailx sends the message.

Unlike followup, reply does not automatically create a file to record your reply. It only does so if the mailx variable record is set, in which case the message will be written to the file defined there. If the file already exists, it is extended.

The reply and respond commands are not permitted in a command file.

Reply[ msglist]
Respond[ msglist]

Replies to the first message in the message list.

mailx switches to send mode and sends the response to the sender of each message in msglist.

When you have completed your input, mailx sends the message.

Unlike Followup, Reply does not automatically create a file to record your reply. It only does so if the mailx variable record is set, in which case the message will be written to the file defined there. If the file already exists, it is extended.

The Reply and Respond commands are not permitted in a command file.

retain[ field]

displays only the specified fields of the message header. The other fields are suppressed. retain displays the specified fields as well, if they are contained in the list of fields to suppress, i.e. retain overrides the effects of discard or ignore.

field not specified:
retain displays the current list of fields to display if available.

save[[ msglist] file]

Saves the indicated messages in the named file, extending it if it already exists.

The messages are marked as saved (S), which means that they are deleted from the default mailbox as soon as you quit mailx, unless you have set the keepsave variable.

No argument specified:
mailx appends the current message to the end of $HOME/mbox.

Save[ msglist]

Saves the specified messages in a file in the current directory. The file name is derived from the name of the sender of the first message in msglist ("From" entry; network addresses are removed). If the file already exists, it is extended.

The messages are marked as saved (S), which means that they are deleted from the default mailbox as soon as you quit mailx, unless you have set the keepsave variable).

set[ name[=value]]

Sets the variable name.

name

Name of a mailx variable or a freely defined variable.

value

Any string or numeric value. \n within value is interpreted as a newline character, \t as a tab.

value not specified:
name is set to the null string.

No argument specified:

Prints all set variables and their values. The values are enclosed in double quotes.

You cannot change the values of environment variables. However, if you define an internal variable of the same name, mailx will use its value until you reset it (this does not apply to the mailx echo command).

The tilde command ~i variable can be used to insert the value of variable in the text of a message.

You can delete variables with unset.

shell

Invokes by default the command interpreter specified in the SHELL variable. If SHELL is not set, /bin/sh will be invoked.

You can specify a different command interpreter with the mailx variable SHELL.

The shell command is not permitted in a command file.

size[ msglist]

Displays the size of the specified messages on standard output in the form message_number: number_of_characters.

source file

Reads the specified file as a command file and executes the mailx commands in it. mailx then returns to the interactive mode (see mailx command and startup files below).

top[ msglist]

Displays the first 5 lines of the header for each specified message on the standard output. You can change the number of lines displayed with the mailx variable toplines.

touch[ msglist]

Causes the specified messages to be trated as read, i.e. they are copied to the user-specific mailbox upon termination of the default mailbox and then deleted from the current one. The user-specific mailbox is $HOME/mbox or the file defined by the MBOX variable.

This does not apply to messages that were saved with save or Save.

touch cancels the effect of hold and vice versa.

type[ msglist]

Prints the specified messages on standard output (see print on "mailx interactive message processing system (mail extended)").

Type[ msglist]

Like print, except that the whole header is always displayed (see Print on "mailx interactive message processing system (mail extended)").

unalias[ alias-name]...

Deletes the specified alias names.

undelete[ msglist]

Restores the specified messages provided they were deleted during the current session. The messages are marked as read (R).

If the autoprint variable is set, the last restored message is displayed.

msglist not specified:
If msglist is not specified, it defaults to the first deleted message following the current message that has not been undeleted if there is one, or the last deleted message preceding the current message that has not been undeleted otherwise.

undiscard[ field]
unignore[ field]

Deletes the specified header fields from the list of fields being ignored.

field not specified:
Deletes the whole of the list of fields being ignored.

unset[ name...]
set[ noname...]

Deletes the specified variables.

If you delete a variable with the same name as an environment variable, you can access the value of the corresponding environment variable again.

version

Displays the current version and release number of mailx.

visual[ msglist]

Invokes the editor specified by the mailx variable VISUAL (default editor: vi) and loads the indicated messages.

The edited message is placed in the mailbox at the end of the editing session.

The text is processed in a temporary file named /tmp/Re$$, where $$ is the process ID of the mailx process.

The visual command is not permitted in a command file.

write[ msglist] file

Writes the specified messages in the named file. If the file already exists, it is extended.

write does not copy the header and the trailing blank line.

The messages are marked as saved (S) in the header summary. They are deleted from the default mailbox as soon as you quit mailx, unless you have set the keepsave variable.

xit

Exits from mailx without changing the current mailbox (see exit on "mailx interactive message processing system (mail extended)").

z[+|]

Scrolls the header display one page forward (z+) or back (z-). The number of lines per page is set by the screen variable. If screen is not set, 20 lines are displayed by default.

+|− not specified:
Same as z+.

Functionality in read mode

At start-up time, mailx will take the following steps in sequence:

  1. Establish all variables at their stated default values.

  2. Process command-line options, overriding corresponding default values.

  3. Import any of the DEAD, EDITOR, MBOX, LISTER, PAGER, SHELL or VISUAL variables that are present in the environment, overriding the corresponding default values.

  4. Read mailx commands from an unspecified system start-up file, unless the -n option is given to initialize any internal mailx variables and aliases.

  5. Process the start-up file of mailx commands named in the user MAILRC variable.

If no mail is present, mailx issues the message:

No mail for login_name

If mail has been received, mailx responds with a message line, an overview of all messages currently in the mailbox, and the mailx prompt ?. You can now enter mailx commands.You can use the ?, help and list command to get a list of all the available commands.

Headers

When you call mailx or use one of the mailx commands from, headers or z, mailx displays a header line for each message present. A header can have up to 9 blank-separated fields, e.g.:

N 1 hadea Mon Sep 21 13:05 10/164 Beeblebrox

These fields refer to:

N

Processing status (see next subsection)

1

Message number. The messages are renumbered each time mailx is invoked. The oldest message is numbered 1.

hadea

Sender

Mon Sep 21

Date message received

13:05

Time message received

10/164

Size of message in lines/characters

Nicowerfel

Title (first 25 characters of subject entry)


Processing status

The processing status is the entry in the first header field. The status will be one of the following:

O

(old)

The message has been read by a previous mailx call. It will be stored in $HOME/mbox, when you quit mailx or close the default mailbox.

U

(unread)

The message has been present in the system mailbox for more than one invocation of mailx and has not yet been read. It will be preserved in the current mailbox when you quit mailx using quit.

R

(read)

The message has been read. It will be saved in $HOME/mbox, if you quit mailx or the default mailbox.

N

(new)

The message has arrived since you last called mailx or changed mailboxes. Messages in state new when mailx quits will be retained in the system mailbox.

M

(mbox)

The message has been saved with mbox.

H

(hold)

The message has been marked by the hold or preserve command. It will stay in the default mailbox when you close it.

S

(save)

The message has been saved with a save, Save or write. It will be deleted from the default mailbox when you close it.

>c

This is the current message. This is the message referenced by mailx commands if you do leave msglist unspecified. The character c stands for any of the above status characters.


User-specific mailbox

Messages are written to the user-specific mailbox if

  • you have read them but not deleted or explicitly saved them

  • you have manipulated them with mbox or touch

  • you have switched from the default mailbox to another mailbox using the file or folder command

  • you have quit mailx with quit (except where the variable hold is set, then the messages remain in the standard mailbox).

The user-specific mailbox is $HOME/mbox or the file defined by the mailx variable MBOX. The file is extended if it already exists. If you use the -f when you call mailx, you can process this file with mailx commands in exactly the same way as the default mailbox.

Send mode


Format 2: mailx[ option]... recipient ...


No option specified

mailx behaves as described in “Functionality in send mode”.

-F

(file)

mailx records all outgoing messages in a file named after the first specified recipient. This file is created in your home directory and can be processed with mailx like a mailbox.

-F not specified:
mailx searches for the record file defined in the mailx variable record. Nothing is recorded if this variable is not set.

-i

mailx ignores the SIGINT signal (see also the mailx variable ignore).

-n

mailx does not initialize from the global startup file /etc/mail/mailx.rc (see "mailx command and startup files" below).

-s subject

(subject)

mailx enters subject in the Subject: header field. of the header summary. This allows you to indicate the subject of the message.

subject
Any string. If the string includes blanks or special characters, it must be enclosed in double quotes.

recipient

One or more recipients. recipient can be:

  • E-mail address (if you are using MAIL of the interNet Services)

  • a login name on the local system

  • an alias group (see mailx read-mode command alias)

  • a pipe symbol followed by a shell command

If recipient begins with a pipe symbol (|), the rest of the name is taken to be a shell command to pipe the message through.

mailx commands in send mode (tilde commands)

Input format

Apart from being preceded by an escape symbol, mailx send-mode commands have the same format as read-mode commands.

[command][ msglist][ argument]...


~

Tilde as escape symbol. The mailx variable escape can be used to define a different character as the escape symbol. But the different character must not be a character which describes a command (e.g. ? or !).

command msglist argument

As described above under mailx commands in send mode, “Input format”.

Functional overview

This section provides an overview of all mailx send-mode commands, grouped by function. Some commands may appear more than once.
The overview is followed by descriptions of all the commands in alphabetical order.

Help functions

~?

Display summary of tilde commands

~p

Display message being entered


Terminating/aborting text input

~.

Terminate input and send

~x

Abort input and do not send

~q

Abort input and save but do not send


Inserting values of variables, old messages and files

~a

Insert value of sign variable

~A

Insert value of Sign variable

~i

Insert value of mailx or environment variable

~d

Insert contents of $HOME/dead.letter

~f

Insert old messages

~F

Insert old messages

~m

Insert old messages

~M

Insert old messages

~r

Insert contents of named file

~<

Insert contents of named file


Invoking command interpreters, running shell commands

~!

Escape to shell

~<!

Run shell command and insert output in text

~|

Pass text to shell command and replace with command output


Displaying text

~p

Display message being entered


Editing text

~e

Call editor to edit text (default: ed)

~v

Call editor to edit text (default: vi)


Modifying mailing lists

~b

Add names to Bcc list

~c

Add names to Cc list

~t

Add names to To list

~h

Edit To, Subject, Cc and Bcc fields


Manipulating the message header

~c

Add names to Cc list

~t

Add names to To list

~h

Edit To, Subject, Cc and Bcc fields

~s

Replace contents of Subject field


Recording text

~w

Write message being entered to file, omitting header

~q

Abort input and save text but do not send


Send-mode commands which expect mailx to have been called in read mode

~_

Execute mailx command

~:

Execute mailx command

~f

Insert old messages

~F

Insert old messages

~m

Insert old messages

~M

Insert old messages


Executing mailx read-mode commands

~_

Execute mailx read-mode command

~:

Execute mailx read-mode command

Descriptions in alphabetical order

mailx commands in send mode (tilde commands) must start with an escape symbol in column one. The default escape symbol is a tilde ( ̃), but this can be redefined with the mailx variable escape.

Tilde commands are not permitted in a command file.


~! shell-command

executes the specified shell_command. Invokes by default the command interpreter specified in the SHELL variable. If SHELL is not set, /bin/sh will be invoked.

~.

Terminates message input and sends the message.

If you are working via rlogin on a remote computer, this tilde command will be interpreted as an instruction to clear down the connection, with the result that the remote session will be terminated immediately. Here are some possible solutions:

  • redefine the escape symbol with the mailx variable escape

  • set the mailx variable dot, so that you can terminate input simply with a dot in
    column one

  • terminate input with CTRL+D

~:mailx-read-command

~_mailx-read-kommand

Executes the specified mailx read-mode command.

You must have invoked mailx in read mode (and then switched to send mode with a mailx command such as mail). Otherwise, mailx will only execute commands that have nothing to do with the processing of a mailbox (e.g. set or exit).

The underscore in the second format is mandatory.

~?

Displays a summary of all tilde commands.

~a

(a - autograph)

Inserts the value of the mailx variable sign in the message.

~A

(A - autograph)

Inserts the value of the mailx variable Sign in the message.

This enables you to define an alternate sign-off string, for example.

~b name...

(b - blind carbon copy)

Adds one or more names to the blind carbon copy (Bcc) list. The Bcc list contains the names of additional recipients of the message. These names are not included in the header.

~c name...

(c - carbon copy)

Adds one or more names to the carbon copy (Cc) list. The Cc list contains the names of additional recipients. These names are included as part of the header information (the Cc entry).

~d

(d - dead.letter)

Reads the contents of the file $HOME/dead.letter into the message. This file contains messages which mailx could not send or which you aborted with ~q.

~e

(e - editor ed)

Invokes the editor specified by the mailx variable EDITOR (default editor: ed) and loads the partial message. Input of the partial message may be continued after the editing session.

~f[ msglist]

(f - file)

Inserts the specified messages, without alteration, into the message text.

This command is only executed if mailx was invoked in read mode (Format 1).

~F[ msglist]

works like ~f, but inserts always the whole message header. discard, ignore and retain will be ignored.

~h

(h - header)

Prompts successively for the following information:

To:

Recipient

Subject:

Subject of the message

Cc:

Carbon copy list containing additional recipients of the message; the names in this list appear in the Cc field of the header

Bcc:

Blind carbon copy list. Like Cc, except that the names do not appear in the header

The fields are displayed with existing values (if any), which you can edit as if you had just entered them.

~i

(i - insert)

Inserts the value of the named variable into the message text. The named variable can be a mailx variable or an environment variable.

~m[ nachrichtenliste]

(m - move)

Inserts the indicated messages into the text, shifting each line one tab stop to the right.

This command is executed only if mailx was invoked in read mode (Format 1).

~M[ nachrichtenliste]

works like ~m, but inserts always the whole message header. discard, ignore and retain will be ignored.

~p

(p - print)

Displays the message being entered.

~q

(q - quit)

Quits input mode by simulating an interrupt. The input text is not aborted but saved in the $HOME/dead.letter file. This tilde command has the same effect as CTRL+C except that it cannot be suppressed with the ignore variable.

~r file
~r !shell-command
~< file
~< !shell-command

(r - read)

Inserts the contents of file or the output of shell_command into the message text.

~s zeichenkette...

(s - subject)

Sets the Subject field of the header to the specified string. Multiple blank-separated strings do not need to be quoted.

~t recipient...

(t - to)

Adds the indicated names of one or more recipients to the "To" field of the header. Multiple names must be separated by blanks.

~v

(v - editor vi)

Invokes the screen editor identified by the mailx variable VISUAL (default editor: vi) and loads the partially entered message. Input of the edited message can be continued on completion of the editing session.

~w  file

(w - write)

Copies the partially entered message, without the header, into the specified file. If the file does not exist, it will be created. Otherwise the message is appended to the specified file.

~x

(x - xit)

Exits, aborting the message being entered. The partially entered message is neither sent nor saved.

~| shell-command

Pipes the current text of the message to the standard input of shell_command. If the shell command returns an exit status of 0, the current text is replaced by the output of the command.

Invokes by default the command interpreter specified in the SHELL variable. If SHELL is not set, /bin/sh will be invoked.

Functionality in send mode

When you call mailx, it first processes startup files. These files may be used to initialize mailx variables, for example (see mailx command and startup files).

Then, unless you use the -s option to specify a message subject, mailx displays:

Subject:

and expects you to enter the subject of the message. This line, which may consist of up to 1024 characters, is written by mailx into the Subject: field of the message header. If the subject is too long, mailx will print the message mail: ERROR signal 10, and the mail will not be delivered.

mailx will now be in send mode, which means that you can enter your message text. All mailx tilde commands are permitted during text input. They must start in column 1. Once you have sent off a tilde command with the enter key, mailx redisplays the whole of the command you have entered in the same line, followed by the string (continue) when it has finished executing the command. If you use one of the commands for inserting text into your message text (such as ~a), mailx will not echo the text on the screen. You can view the original text and the inserted text with the ~p command.

mailx stores the input text in a temporary file in the /tmp directory.

The command ~. or CTRL+D signals the end of input.


Tilde commands in read mode

Some tilde commands only offer their full functionality if you call mailx in read mode (Format 1) and temporarily switch from there to send mode. The commands in question are: ~_ and ~: (execute mailx command) and ~f and ~m (insert old messages).

The read commands you can use to switch temporarily to send mode so as to send or reply to a message are followup, Followup, mail, Mail, reply, Reply, respond and Respond.

mailx command and startup files

Command files

Command files are files that contain mailx commands. Each mailx command must be entered in a separate line. You can execute command files by using the source command during a mailx session, or you can use them as startup files (see below).

Tilde commands are not permitted in command files, and nor are the commands !, edit, followup, Followup, mail, Mail, reply, Reply, respond, Respond, shell and visual.

The copy, Copy, hold and preserve commands are permitted, but then any subsequent commands which are intended to operate on a message list will be ignored.

If an error occurs in a command file, mailx ignores all subsequent commands in the file. An error also occurs if a message list refers to a non-existent message (see Example 2).


Startup files

Startup files are command files that mailx processes every time it is invoked, unless you call it in read mode using the -e or -n options.

mailx first processes the global startup file /etc/mail/mail.rc, followed by the private startup file $HOME/.mailrc, provided such files exist. You can redefine the path name of the private startup file with the MAILRC variable.

The mailx commands in the startup files may not use msglist, because this information is not yet provided when executing the startup files.

Variables

mailx utilizes environment variables, mailx variables and freely defined variables.

All variables can be imported, and during a mailx session they can be set and reassigned with the set command and deleted with unset.

mailx variables, i.e. all variables consisting of lowercase letters only, can only be set within mailx (e.g. in startup files). Contents of shell variables with the same names are not inherited by mailx variables.

If you use set to reassign an imported variable, the new value applies until you change it again, delete it with unset or end your mailx session.

The mailx command echo always references the original value of an imported variable.

asksub, header and save are enabled by default.

Of the variables which can be assigned values, the following have default values:

  • DEAD=$HOME/dead.letter

  • EDITOR=ed

  • escape= ̃

  • MBOX=$HOME/mbox

  • LISTER=ls

  • PAGER=more

  • prompt=?

  • screen=20

  • SHELL=/bin/sh

  • toplines=5

  • VISUAL=vi

The references to Associated commands in the following list relate to the mailx commands particularly affected by the setting or deletion of the variable in question.

mailx variables

allnet

mailx treats all network names ending with matching login names as identical. Addresses in the form ...computer_name!computer_name!login_name are treated as network names. See also the metoo variable.

Default value: The variable is not set.

append

Appends messages saved in the user-specific mailbox ($HOME/mbox by default) to the end of the file.

Associated commands: copy, Copy, file, folder, mbox, next, print, Print, type, Type, quit, touch

Default value: The variable is not set.

ask
asksub

Causes mailx to prompt for the subject when invoked (see also option -s).

Associated commands: ~h, ~s

Default value: The variable is set.

askbcc

mailx prompts for the Bcc list after the subject is entered.

Associated commands: ~c, ~h

Default value: The variable is not set.

askcc

mailx prompts for the Cc list after the subject is entered.

Associated commands: ~c, ~h

Default value: The variable is not set.

autoprint

Displays the next message after the delete command, and the restored message after the undelete command.

Default value: The variable is not set.

bang

Causes mailx to remember the last command executed with !shell_command. You can then repeat the command by entering !!.

Default value: The variable is not set.

cmd=shell_command

Sets the default command used by pipe and | to the specified shell_command (only used if no command is specified in pipe).

Default value: None.

crt=number

Pipes message output having more than number lines through the command specified by the PAGER variable (PAGER=more by default).

Associated commands: dp, dt, next, print, Print, type, Type,~p

Default value: The variable is not set.

debug

Enables diagnostics for debugging. If you set this variable, mail will not be delivered.

Default value: The variable is not set.

dot

Causes a line consisting solely of a dot in column one to terminate input (instead of the command ~.).

Default value: The variable is not set.

escape=c

Substitutes c for the tilde escape symbol. c may not be a character describing a command (e.g. ? or !)

Default value: ~

flipr

The effects of the commands reply, respond and Reply, Respond are exchanged.

Associated commands: reply, Reply, respond, Respond

Default value: The variable is not set.

folder=directory

If both folder and outfolder are set, reply texts with the followup and Followup commands will be recorded in directory, not in the current directory. If directory does not begin with a slash, mailx sets the directory name to $HOME/directory.

You can also use the form +filename to reference these record files in any mailx command which accepts file names. mailx will then expand the name by prepending directory.

Default value: The variable is not set.

header

Causes the header summary, the current mailx version string and the number of messages to be displayed when mailx is invoked.

Default value: The variable is set.

hold

Preserves read messages in the default mailbox instead of putting them in the user-specific mailbox file (also refer to MBOX Environment Variables on "mailx interactive message processing system (mail extended)").

Associated commands: copy, hold, mbox, next, preserve, print, Print, quit, touch, type, Type

Default value: The variable is not set.

ignore

Ignores the SIGINT signal during message input.

Associated commands: followup, Followup, mail, Mail, reply, Reply, respond, Respond, ~q (CTRL+C)

Default value: The variable is not set.

ignoreeof

The end-of-file signal (EOF, CTRL+D) is to be ignored during message input (also refer to the dot variable on "mailx interactive message processing system (mail extended)").

Associated commands: followup, Followup, mail, Mail, reply, Reply, respond, Respond, ~.

Default value: The variable is not set.

indentprefix=string

During the insertion of a message into a text each line of the message begins with string.

Associated commands:  ~m, ~M

Default value: Tab character.

keep

The mailbox should not be deleted when it is empty.

Default value: The variable is not set.

keepsave

Messages that are marked as saved (S) in the header are not to be deleted from the default mailbox.

Associated commands: save, Save, write

Default value: The variable is not set.

metoo

If your own login name appears in the list of recipients ("To" list), it is not deleted from the list. See also the mailx command alias and the allnet variable.

Associated commands: alias, alternates, followup, group, reply, respond, ~h

Default value: The variable is not set.

outfolder

If both outfolder and folder are set, reply files with the followup and Followup commands will be stored in the directory defined by folder (also refer to record variable on "mailx interactive message processing system (mail extended)").

If only outfolder (or only folder) is set, reply files will be stored in the current directory.

Default value: The variable is not set.

page

Causes a form feed character (FF = CTRL+L = X’0C’) to be inserted after each message routed through a pipe or | command.

Default value: The variable is not set.

prompt=string

Sets the input prompt for mailx read-mode commands to string.

Default value: ?

quiet

Suppresses the display of the opening message and version identifier when mailx is invoked.

Default value: The variable is not set.

record=file

Records all outgoing mail in the named file. The file is extended if it already exists.

Associated commands: mail, Mail, reply, Reply, respond, Respond, ~.

Default value: The variable is not set.

save

Saves messages that could not be sent, e.g. due to an error or an interrupt from CTRL+C during input. These messages are saved in the file specified by the DEAD variable.

Associated commands: followup, Followup, mail, Mail, reply, Reply, respond, Respond, ~d, ~q (CTRL+C)

Default value: The variable is set.

screen=number

mailx displays number header lines.

Associated commands: header

Default value: Dependent on the terminal type specified by TERM, usually 20

sendwait

After a read command, waits for the background mailer to finish before returning control to the user.

Associated commands: followup, Followup, mail, Mail, reply, Reply, respond, Respond

Default value: The variable is not set.

showto

If you send a message and include yourself among the recipients, the name of the first recipient in the recipient list (To list) will appear in the header list displayed, not your login name.

Associated commands: from, headers, z+, z-

Default value: The variable is not set.

sign=string

Defines an autograph string to be inserted into the text of a message.

Associated commands: ~a, ~i

Default value: The variable is not set.

Sign=string

Defines an (additional) autograph string to be inserted into the text of a message.

Associated commands: ~A, ~i

Default value: The variable is not set.

toplines=number

mailx displays number lines from the message header.

Associated commands: top

Default value: 5

Error

mailx’s error messages are largely self-explanatory.

File

/etc/mail/mail.rc

Global startup file

$HOME/.mailrc

Private startup file

/var/mail/$USER

The default mailbox that is searched by mailx for incoming messages.

$HOME/mbox

User-specific mailbox in which mailx saves messages that have been read.

$HOME/dead.letter

File that is used by mailx to save messages that could not be sent, e.g. due to an error or an interrupt with CTRL+C during input. If the file already exists, it is overwritten.

./<username>

Files created in the current directory with names derived from a login name. These files are created by mailx in response to the following commands:
Copy, followup, Followup, Save.

You can also select some other directory instead of the current directory (see the mailx variables folder ("mailx interactive message processing system (mail extended)") and outfolder ("mailx interactive message processing system (mail extended)")).

/tmp/R[emsxz]*

Temporary files.

/tmp/Rz$$

Temporary file used by the commands edit, visual, ̃e, and ̃v. $$ is the process ID of the mailx process.

/usr/share/lib/mailx/mailx.help*

Help message files

Environment variables

DEAD=file

The named file is used by mailx to save messages that could not be sent, e.g. due to an error or an interrupt during input. This file is extended if it already exists.

Associated commands: followup, Followup, mail, Mail, reply, Reply, respond, Respond, ~d, ~q (CTRL+C)

Default value: $HOME/dead.letter

EDITOR=shell_command

In a mailx session, message texts can be edited with the editor named as shell_command (also refer to mailx variable VISUAL ("mailx interactive message processing system (mail extended)")).

Default value: ed.

HOME=directory

Home directory.
Specifies the default directory in which mailx creates or searches for the files dead.letter, mbox, .mailrc, and the files used to record outgoing messages (see the commands followup ("mailx interactive message processing system (mail extended)"), Followup and  ~f ).

LISTER=shell_command

Uses shell_command to list files in the folder directory.

Associated commands: folders

Default value: ls

MAILRC=file

file defines the name of the private startup file (default: $HOME/.mailrc; see “mailx command and startup files”).

MBOX=file

file designates the user-specific mailbox in which mailx is to save read messages before removing them. Each additional message extends the file (also refer to the hold variable on "mailx interactive message processing system (mail extended)").

Associated commands: copy, hold, mbox, next, preserve, print, Print, quit, save, touch, type, Type

Default value: $HOME/mbox

PAGER=shell_command

Uses the specified shell_command for the paging of output that exceeds the number of lines defined in the crt variable.

Associated commands: dp, dt, next, print, Print, type, Type, ̃p

Default value: more

SHELL=shell_command

shell-kommando legt den Kommando-Interpreter fest, den mailx benutzt, um POSIX-Kommandos auszuführen.

Relevante Kommandos: !, shell

Standard-Wert: /bin/sh

TERM

Contains information about the terminal type. The TERM variable will be evaluated if the mailx variable screen is not set.

USER

The USER variable tells mailx the login name of the user, to enable it to identify the default mailbox etc.

VISUAL=shell_command

In a mailx session, message texts can be edited with the editor named as shell_command.

Associated commands: visual, ~v

Default value: vi.

Locale

The following environment variables affect the execution of mailx:

LANG

Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined.

LC_ALL

If set to a non-empty string value, override the values of all the other internationalization variables.

LC_CTYPE

Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other.

LC_MESSAGES

Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error.

NLSPATH

Determine the location of message catalogs for the processing of LC_MESSAGES.

Example 1

Replying to a message

User marvin receives the message you have mail, so he calls mailx without options. He sees a few lines of text and some header lines, has all his messages displayed one after the other (using the enter key, for example) and finally replies to the fourth message. The text of his reply is to be recorded in the current directory (followup or fo). While in send mode, he changes the Subject entry assigned automatically by mailx (~s) and inserts his sign-off string, as defined in his sign variable, at the end of the text (~a). Before sending his letter (~.), he has it redisplayed (~p) and then quits mailx with xit or x so as to retain all his messages in the mailbox.

mailx

mailx version 4.0 Type ? for help

"var/mail/MARVIN": 4 messages 4 new

>N 1   ARTHUR     Fri Sep  6   9:21    13/373      betelgeuse

 N 2   FRODO      Fri Sep  6  12:00    13/365      sysadm

 N 3   PETER      Mon Sep 16  10:01     9/232      qed
 N 4   BENNY      Tue Sep 17  16:43    21/593      Project S

<enter key>

 :

fo BENNY

To: <BENNY>

Subject: Re: Project S

~s Final report on P S ~s Final report on P S
.

.

~a   ~a

~p   ~a

--------

Message contains:

To: <BENNY>

Subject: Final report on P S

Hi there, Ben!

Thanks for the minutes. What I really need is the final report itself,

 and not just Real Soon Now, but tomorrow at the latest. I need a

 printed version, not just a file.
 Regards,

 (-: marvin :-)

 (continue)

  ̃.

 ? x
 Held 4 messages in /var/mail/MARVIN
 $

Example 2

Example of a startup file

The following startup file sets variables and prints all messages from winnie (with lp) when mailx is invoked in read mode.

# Processing variables
set page crt=24 cmd=lp VISUAL
set sign="\n\tFord Prefect\n\tSales Division\n\t Detroit"
# Sender: Network system administrator
alias sys root@orlando root@annapolis root@chicago
# Prints specific mail
if r
pipe winnie lp
from winnie
endif

Note that mailx terminates the script if any command cannot be executed. This might be the case here with the pipe command if no messages from winnie were present. In other words, mailx then would not execute the from command (or any others that might follow).

See also

ed, ls, more, sh, vi