mailx, Mail - Sends and receives mail
mailx [-dinvF] [-h number] [-r address] [-s subject] user...
Mail [-dinvF] [-h number] [-r address] [-s subject] user...
mailx [-dinNveH] -f [file]
Mail [-dinNveH] -f [file]
mailx [-dinNveH] [-u user]
Mail [-dinNveH] [-u user]
The mailx and Mail commands allow you to read, write, send, receive, store, and discard mail messages.
[Compaq] See the section Internationalization under the
section for more information about the internationalization features of the
Interfaces documented on this reference page conform to industry standards as follows:
Refer to the
reference page for more information
about industry standards and associated tags.
command to display debugging
information. Messages are not sent while in debug mode.
Tests for the presence of mail. The
command prints nothing and exits with a successful return code if there is
mail to read.
Reads in the contents of your
specified file for processing. When you quit,
undeleted messages back to this file.
Records the message in a file named after the first recipient.
option, if set.
Specifies the number of network ``hops'' made so
far. This is provided for network software to avoid infinite loops.
Prints header summary only.
Ignores tty Interrupt signals. Useful when using
on noisy phone lines.
Inhibits the reading of the
Suppresses the initial printing of headers.
to the network delivery
software. All tilde commands are disabled.
Specifies a subject for a message to be created.
for a specified users mailbox;
short way of doing
mailx -f /var/spool/mail/user. You must have access permission to the specified user's
into verbose mode. Details
of delivery are displayed on the user's terminal.
The mailx and Mail commands allow you to do the following: Compose a message and send it. Receive a message and look at it. Store received messages in your mailbox or in folders. Discard messages.
The mailx command uses two types of mailboxes: the system mailbox and the personal mailbox. The system mailbox is a file assigned to a particular user. The file is created when mail arrives for a user ID, and it is deleted when all the messages are removed from the file. It is not deleted if you have specified the keep option in your .mailrc file, or if the /var/spool/mail directory has no write permissions for other. A separate system mailbox can exist for each user ID on the system. The mailx command keeps all system mailboxes in the directory /var/spool/mail. Each system mailbox is named by the user ID associated with it. For example, if your user ID is jeanne, then your system mailbox is /var/spool/mail/jeanne.
The personal mailbox is a file assigned to a particular user. The mailx command creates a file with the name $HOME/mbox when you receive mail from the system mailbox. For example, if your home directory is /u/lance, the mailx command creates the file /u/lance/mbox as your personal mailbox. The system deletes this file when all messages are removed from the personal mailbox. When you use the mailx command to view mail in your system mailbox, the mailx command automatically puts all messages that you have read but did not delete into your personal mailbox. The messages remain in your personal mailbox until you move them to a folder or delete them.
Folders provide a way to save messages in an organized fashion. You can create as many folders as you need. Name each folder according to the subject matter of the messages that it contains. Using the mailx command, you can put a message into a folder from your system mailbox, from your personal mailbox, from the dead.letter file, or from another folder.
To send a message to one or more persons, enter mailx on the command line with arguments that are the network addresses of the people you want to receive the message. When mailx starts, you can type the message using an editor such as ed. When you are finished with the message, press <Return> at the end of a line, and use an End-of-File key sequence at the beginning of the next line to exit the editor and send the message.
When mail arrives for you from another user, the mail system puts the mail in your system mailbox (/var/spool/mail/user). The command shell will notify you that mail has arrived before displaying its next prompt (that is, notification is synchronous), provided that the MAIL environment variable is set and the interval specified by MAILCHECK (mail for csh) has elapsed since the shell last checked for mail. If you are logged in, the shell sends a message to your terminal to tell you that new mail has arrived. If you are not logged in, a message is sent to your terminal the next time you log in. The notification message is the value of the MAILMSG environment variable. The default message is as follows: [YOU HAVE NEW MAIL]
To look at the contents of your mailbox, enter the mailx command without options on the command line. The program displays a listing of the messages in your mailbox and allows you to look at them, reply to them, save them, dispose of them, and so on.
[Compaq] Tru64 UNIX provides locking for the mailbox files. The
style of locking used depends on how it is set in the
file. For more information, see the
To receive and read incoming mail, enter mailx with no arguments: mailx
command then checks your system mailbox
(/var/spool/mail/user) and displays
a one-line entry for each message in the system mailbox similar to the following:
"/var/spool/mail/geo": 2 messages 2 new
>N 1 amy Thu Sep 17 14:36 13/359 "Dept Meeting"
N 2 amy Thu Sep 17 16:28 13/416 "Dept Meeting Delayed"
The > (right angle bracket) indicates the current message, or the message that subcommands act on if you do not specify a message number or list of message numbers. The first field for each message contains a one-letter indicator of the status of the message. Possible indicators are as follows: The message is stored in your personal mailbox. The message is new. The message is held (preserved) in your system mailbox. You have read the message. The message is unread. The message was listed in the mailbox before, but you have not looked at the contents of the message. You have saved or written the message to a file or folder. The message was read, but was not deleted or saved.
The other fields in the listing (in order) represent: The number that mailbox subcommands use to refer to the message. User address of the sender. Date the message was received, including day of the week, month, day, and time. Size of the message in number of lines and characters, including header information. The contents of the subject field of the message, if the message has one.
From the mailbox prompt (?), you can enter subcommands to look at, reply to, save, discard, or otherwise manage the contents of the mailbox. To display a summary of some of the subcommands that you can use to handle mail in your mailbox, enter a ? (question mark) at the mailbox prompt. Note that the behavior of the <Return> key has changed for XPG4 compliance. Using this key with no following argument now causes the current message to be displayed, and not the next message.
Many mailbox subcommands allow you to specify groups of messages upon which to perform the subcommand. Subcommands that allow groups of messages use the argument message_list in the command format. For example, the format of the from (or f) subcommand (display information about messages) appears as:
? from [message_list]
In this format, message_list can be one of the following: One or more message numbers separated by spaces. For example:
The special character . (dot) addresses the current message, * (asterisk) addresses all messages, ^ (circumflex) addresses the first undeleted message, and $ (dollar sign) addresses the last message. The character sequence :c addresses all messages of type c, where c is one of the following: Deleted messages New messages Old messages Read messages Unread messages
All commands that take a message list will default to the current message number if no list is specified.
When the mailx command is processing a mailbox, the mailbox prompt (?) is displayed to indicate that it is waiting for input. When this prompt is displayed, you can enter any of the following mailbox subcommands. The subcommand abbreviation in parentheses can be used instead of the full subcommand name. Echoes the number of the current message. Allows you to write comments in mail script files. Goes to the previous message and displays it. If given a number argument of n, goes to the nth previous message and displays it. Displays a brief summary of mailbox subcommands. Executes shell_command. Displays all currently defined aliases. With the argument of a previously defined alias, displays the expansion of the alias. With two arguments (alias and address_list), creates a new alias or changes an old alias. Identical to the group subcommand. Informs mailx that the addresses listed in alternate_list all refer to you. The alternates subcommand is useful if you have accounts on several machines. Then, when you reply to messages, mailx does not send a copy of the message to any of the addresses given in alternate_list. If you enter the alternate subcommand with no argument, mailx displays the current set of alternate names. Changes your working directory to directory. If no directory is given, it changes to your login directory. Appends each message in message_list in turn to the end of file. Displays the filename in quotes, followed by the line count and character count, on your terminal. Does not mark the appended messages for deletion when you quit. Saves 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 subcommand. Marks the messages in message_list to be deleted when you quit mailx. Deleted messages are not saved in mbox, nor are they available for most other subcommands. However, you can restore messages that you have deleted while in the same mailbox session (see the undelete subcommand). If you delete a message and either change to another mailbox or quit the mailbox with the quit subcommand, the deleted message cannot be recalled. Identical to the ignore subcommand. Deletes the current message and displays the next message. If there is no next message, mailx displays the message, at EOF. Identical to the dp subcommand. Displays the character string string on the command line. Invokes the alternate editor that you can define with the set EDITOR= statement and loads message_list into the editor. When you exit the editor, any changes made during the editing session are saved in the messages in message_list. The default editor is /usr/bin/ex. Exits to the shell without changing the mailbox being processed. The mailbox returns to the condition that it was in when mailx was started. Messages marked to be deleted are not deleted. Identical to the xit subcommand. Identical to the folder subcommand. Switches to a new mail file or folder. With no arguments, displays the name of the mailbox that you are currently reading. If an argument is included, it stores the current mailbox with changes (such as messages deleted) and reads in the new mailbox specified by the name argument. Identical to the file subcommand.
You can use the mailx command in one of two ways to send information. You can use the mailx command's built-in editor to both compose and send a short message. You can also use the mailx command to send any text file to another user. The file can be a letter you have written using your favorite editor, a source file for a program you have written, or any other file in text format.
The mailx command provides a line-oriented editor for composing messages. This editor allows you to enter each line of the message and then press <Return> to get a new line to enter more text. You cannot change the text after you press <Return>. However, before you press <Return>, you can change text on the current line by using <Backspace> and <Delete> to erase the text and then enter the replacement text. Although you cannot change text on a line once you have pressed <Return>, you can change the contents of your message before sending it by using the visual or edit subcommand to edit the message.
By default, mailx treats lines beginning with the ~ (tilde) character as special while you are composing a message. For instance, entering ~m on a line by itself places a copy of the current message into the response, shifting it to the right by one tab stop.
Other escapes set up subject fields, add and delete recipients of the message, and allow you to escape to an editor to revise the message, or to a shell to run other commands. You can change the Escape character to something other than a tilde with the set escape= statement. To view a summary of many useful commands, enter ~? on a line by itself while in the mail editor.
The following list provides a summary of the mail editor commands. Use these commands only while in the mail editor. The editor recognizes commands only if you enter them at the beginning of a new line. Escapes to command mode. Displays a summary of the mailx subcommands. Executes the shell command and returns to the message. Simulates End-of-File (terminates message input). Performs the command-level request. Valid only when sending a message while reading mail. Inserts the autograph string from the sign= option into the message. Inserts the autograph string from the Sign= option into the message. Adds names in address_list to the list of people to receive blind copies of the message. Can only be used to add to (not to change or delete) the contents of the Bcc: list. Adds names in address_list to the list of people to receive copies of the message. Can only be used to add to (not to change or delete) the contents of the Cc: list. Dumps core. Appends the file dead.letter from your home directory to the current end of the message. Invokes the alternate editor using the text of the current message as input. (This editor can be defined with the set EDITOR= statement.) When you exit that editor, you return to the mail editor, where you can continue appending text to the message, or you can send the message by quitting the mailx command. Includes one or more additional messages in the current message to forward to another user. This subcommand reads each message in message_list and appends it to the end of the current message, but it does not indent the appended messages. This subcommand is also used to append messages for reference when the margins are too wide to imbed with the ~m subcommand. The ~f subcommand works only if you entered the mail editor from the mailbox prompt using the mail subcommand, the reply subcommand, or the Reply subcommand. Performs the same operation as the ~f command escape, except that all headers are included in the message, regardless of previous discard, ignore, and retain commands. Allows you to add or to change information in all of the header fields. The system displays each of the four header fields, one at a time. You can view the contents of each field and delete or add information to that field. Press <Return> to save any changes to that field and to display the next field and its contents. Inserts the value of the named option into the text of the message. For example, ~A is equivalent to ~i Sign. Reads message_list into the current messagefor reference purposes. This subcommand reads each message in message_list and appends it to the current message. The included message is indented one tab character from the normal left margin of the message. This subcommand works only if you entered the mail editor from the mailbox prompt using the mail subcommand, the reply subcommand, or the Reply subcommand. If no messages are specified, it reads the current message. Performs the same operation as the ~m command escape, except that all headers are included in the message, regardless of previous discard, ignore, and retain commands. Displays the message as it currently exists, prefaced by the message header fields. Quits the editor, aborting the message being created without sending it. Saves the message in the dead.letter file in your home directory, unless the nosave option is set. The previous contents of the dead.letter file are overwritten by the partially completed message.
The system manager uses the /usr/share/lib/Mail.rc file to define the initial configuration for the mailx command. The subcommands in this file override the default characteristics of the mailx command for all users on the system. Although the initial configuration can meet the needs of most users, you can alter it by creating the $HOME/.mailrc file. Subcommands in this file override similar subcommands in /usr/share/lib/Mail.rc when you run the mailx command. The following subcommands are not legal in the start-up file: !, Copy, edit, followup, Followup, hold, mail, preserve, reply, Reply, shell, and visual.
There are four mail subcommands that are most commonly used to alter
the characteristics of the
subcommands enable and disable mail options, the
subcommand shortens how you address mail, and the
subcommand suppresses message header fields.
The following are environment variables taken from the execution environment and are not alterable within mailx: The name of the locale for performing character conversions on outgoing messages. The pathname of the user's home directory. The name of the locale for displaying mail messages. The name of the start-up file. The default is $HOME/.mailrc.
Use the set subcommand to enable options and the unset subcommand to disable options. Options can be either binary or valued. Binary options are either set or unset, while valued options can be set to a specific value. You can set options by placing set subcommand lines in your $HOME/.mailrc file.
The syntax for enabling options using the set subcommand is as follows: set [option_list|option=value]
The syntax for disabling options using the unset subcommand is as follows: unset [option_list]
The following is a list of binary options (those that can be set or unset): Off by default; all network names with the same login name are treated as being the same. Causes messages saved in mbox to be appended (added to the end) rather than prepended (added to the beginning). Causes mailx to prompt you for the subject of each message you send. If you respond with a newline (carriage return), no subject field is set. This option is enabled by default. Causes mailx to prompt you for the address of people to receive blind carbon copies of the message. Responding with a newline indicates satisfaction with the current list. The default is noaskbcc. Causes you to be prompted for the addresses of people to receive copies of the message. Responding with a newline indicates your satisfaction with the current list. Prompts for subject if it is not specified on the command line with the -s option. Identical to ask. Causes the delete subcommand to behave like dp. Thus, after deleting a message, the next one is typed automatically. Enables the special-case treatment of ! (exclamation points) in escape command lines as in vi. The default is nobang. Causes mailx to display debugging information. The mailx command does not send mail while in debug mode. Same as specifying -d on the command line. Causes mailx to interpret a period alone on a line as the terminator of a message you are sending. Reverses the meaning of the R and r commands. The default is noflipr. Enables printing of the header summary when entering mailx. This option is enabled by default. Holds messages in the system mailbox by default. Causes Interrupt signals from your terminal to be ignored and echoed as @'s. Makes mailx refuse to accept End-of-File key sequence as the end of a message or as the quit subcommand. Related to the dot subcommand. Truncates the mailbox to zero length when it is empty, instead of removing it. This option is disabled by default. Keeps messages that have been saved in other files in the mailbox, instead of deleting them. The default is nokeepsave. Causes the sender to be included in the alias expansion, and thus receives copies of messages. Usually, when an alias containing the sender is expanded, the sender is removed from the expansion. Used when replying to a message sent to several users and prevents the addresses of the recipients from being made relative to the address of the original author. You can use this variable only on a network where all systems can connect to one another directly. Prevents mailx from copying the partial letter to the file dead.letter in your home directory when a message is terminated with two Interrupt key sequences. Causes the files used to record outgoing messages to be located in the directory specified by the folder option unless the pathname is absolute. The default is nooutfolder. (See the folder option and the Save, Copy, followup, and Followup subcommands.) Inserts a formfeed after each message sent through the pipe when used with the pipe command. The default is nopage. Suppresses the printing of the program banner when mailx starts. (The banner is the line that shows the name of the mail program.) Reverses the sense of the reply and Reply mailbox subcommands. Enables saving of messages in dead.letter on interrupt or delivery error. (See DEAD= for a description of this file. This option is enabled by default.) Waits for the background mailer to finish before returning. The default is nosendwait. Prints the recipient's name instead of the author's name when displaying the header summary and the message is from the user. Runs mailx in verbose mode; the actual delivery of messages is displayed on the user's terminal. Same as using the -v option on the command line.
The following is a list of valued options (those that can be assigned a value). The syntax for assigning values is set option=value. Sets the default command for the pipe subcommand. There is no default value. Off by default; used to convert uucp addresses for sendmail. Causes the paging program to automatically be invoked for messages that exceed number lines. Specifies the name of the file in which to save partial letters in case of untimely interrupt or delivery errors. The default is $HOME/dead.letter. Defines the text editor invoked by the ~e and edit subcommands. The absolute pathname must be given. The default editor is /usr/bin/ex. Defines a character to use in the place of ~ (tilde) to denote escapes. Sets the locale for performing character conversion on outgoing messages. The default is None. Defines the name of the directory to use for storing folders of messages. If this name begins with a / (slash), mailx considers it to be an absolute pathname; otherwise, the folder directory is found relative to your home directory. Specifies a string that is prefixed to each line inserted into the message by the ~m command escape. The default string is one <Tab> character. Sets the locale for displaying mail messages. The default is C. Specifies the command (and arguments) to use when listing the contents of the folder directory. The default is ls. Specifies the name of the file in which to save messages that have been read. The exit subcommand overrides this function, as does saving the message explicitly in another file. The default is $HOME/mbox. Specifies the pathname of the paging program to use for the more subcommand or when the crt option is set. If you do not specify a value for PAGER, the system uses /usr/bin/pg. Sets the command mode prompt to string. The default is ?. Specifies the pathname of the file (relative to $HOME) used to record all outgoing mail. A copy of all the messages you send out is saved in this file. Review this file periodically and delete all unnecessary messages.
If you send mail on a large network or often send the same message to a large number of people, entering long addresses for each receiver can become tedious. To simplify this process, you can create an alias or a distribution list in your $HOME/.mailrc file.
An alias is a name you define that can be used in place of a user address when you address mail. A distribution list is a name that you define that can be used in place of a group of user addresses when you address mail.
Aliases and distribution lists are used the same way and defined in
similar ways; the only difference is the number of addresses defined for an
alias (one address) and a distribution list (more than one address).
You can use the ignore subcommand to suppress message header fields that are normally displayed when you read a message using the type or print subcommands. The four message header fields are To, Subject, Cc, and Bcc.
The syntax of the ignore subcommand is as follows: ignore [field_list]
Note that fields are specified without a trailing
(colon). You can include the fields you want to ignore in your
[Compaq] The mailx command supports codeset conversion of mail messages between the mail interchange code (specified by the EXCODE environment variable) used to transmit messages to other hosts and the application code (specified by the LANG environment variable) used by the user. For example, if the mail interchange code is ISO-2022-JP and the application code is eucJP, the mailx program converts incoming messages from ISO-2022-JP to the Japanese EUC character set when displaying them and converts outgoing mail message from the Japanese EUC character set to ISO-2022-JP.
To prevent data loss, incoming mail messages are stored in the mail folders as received, without conversion. The conversion takes place when you display or extract mail messages.
To encode the mail interchange code information, new header lines are added to the outgoing mail messages. For example, if the mail interchange code is ISO-2022-JP, the following additional header lines are added:
Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-2022-JP
The charset field of the Content-Type header line provides the mail interchange code information. For non-ISO codesets, the prefix X- is added to the character set name for identification purposes. For example:
Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-eucJP
For incoming mail messages, the mail interchange to be used is determined by the charset field of the additional header lines, if present.
For outgoing mail messages, the following rules determine the mail interchange code to be used: The EXCODE environment variable. The excode valued option defined in $HOME/.mailrc or /usr/share/lib/Mail.rc
The application code is determined from the codeset part of the following locale information: The LANG environment variable. The lang valued option defined in $HOME/.mailrc or /usr/share/lib/Mail.rc Defaults to C.
Note that you must specify a mail interchange code to do character conversion. There are no defaults.
All messages associated with conversion are informational only. The mail messages in question are still delivered or received.
recognized only within
/usr/share/lib/Mail.rc. Setting these options within
To save a message to a folder, enter the following at the mailbox prompt (?): save 1 +procedures
User mailbox files.
Holds saved mail.
subcommands to customize
for a specific user.
subcommands to change
for all users on the system.
Commands: mail(1), fmt(1), pg(1), sendmail(8)