mail - Read and send mail messages
Format
- mail [-e | -p] [-qr] [-f file...]
- mail [-t] name...
Description
mail lets you read mail sent to you and sends mail to other users. It has two modes of operation, one for reading mail and one for sending mail. If you start mail without any arguments, it checks for mail to be read and then presents the messages in read mode. If you start it with an argument or arguments, it assumes you are sending a message to the address named as the argument and enters send mode. The text of the message is taken from standard input until mail encounters either EOF or a line consisting of only a single dot (.).
mail
mail chris lee
Options
- -e
- Tests for the existence of mail and exits. If there is mail in the system mailbox, the return status is successful.
- -f
- Reads mail from file instead of the system mailbox. This option is often used to read mail saved in other files.
- -p
- Prints all mail to standard output without querying.
- -q
- Quits the mail session after an interrupt signal; normally, an interrupt ends only the message being written.
- -r
- Saves messages in first-in, first-out order, the reverse of the default. Normally, the most recently received message is written first.
- -t
- Lists the recipients at the beginning of the message (default).
Reading mail
When you start mail without arguments, mail checks your system mailbox for mail. If there is no mail, mail exits with a return code of 1; if there is waiting mail, mail displays the first message. (If you specify -p on the command line, it displays all messages.)
- d
- Deletes the current message.
- m[name...]
- Sends the current message to the specified user. If a user is not specified, the mail is sent to you.
- p
- Prints the message on the screen again.
- q
- Quits mail, storing any undeleted messages in the file $HOME/mbox.
- s[file]
- Saves the message in the specified file. If a file is not specified, mail saves the message in mbox in your home directory.
- w[file]
- Saves the message (same as s), but without header lines.
- x
- Exits mail without changing the mailbox file.
- ENTER (or newline)
- Displays the next message.
- !command
- Runs command using the shell.
- +
- Displays the next message (same as ENTER or newline).
- -
- Displays the previous message.
- *
- Displays a summary of internal commands.
Because the commands are read from standard input, you can create mail command files and use input redirection to have mail execute them.
Sending mail
To send mail, start mail with a list of addresses as arguments. Enter the text of the message, and end the message with either EOF or with a single dot (.) on a line followed by a <newline>.
The -t option inserts at the beginning of the message a list of the addresses; a path name beginning with a slash (/) is recognized as a valid address (assuming you have the correct permissions).
If the address is not valid or recognized, or if the message is interrupted (see the -q option), mail stores the message in the file dead.letter in the current directory. If it can't create dead.letter in the current directory, it creates the file in your home directory. If dead.letter already exists, the new contents overwrite the old.
The mail program modifies the
message text slightly; because lines beginning with From
(including
the trailing space) are used to separate files in the mailbox, mail changes
any lines in the message that begin with From
to
read >From
.
Examples
mail chris < how2mail
Usage notes
- Wherever the POSIX standard doesn't define the behavior of mail, this implementation resembles mailx.
- mail doesn't require a delivery path or mechanism to the destination, though for most uses, this is preferable.
Environment variables
- HOME
- Specifies your home directory; used to locate the mbox and dead.letter files.
- TZ
- Specifies the time zone to be used in date and time strings.
Localization
- LC_CTYPE
- LC_MESSAGES
- LC_TIME
- NLSPATH
The ability of mail to handle double-byte characters (or even 8-bit ASCII depends on the underlying mail transport mechanism. You should restrict all messages to the POSIX portable character set. To send messages containing double-byte characters or even binary files, encode them first with uuencode.
Files
- dead.letter
- The most recently canceled message.
- mbox
- The default file for saving read mail, stored in the directory specified by HOME.
Exit values
0
- The session was successfully completed; if reading, there was mail.
1
- There was no mail, or the session could not be started.
2
- An error occurred after starting the session, or you supplied an invalid option, resulting in a usage message.
Portability
POSIX.2
Because this utility is due to be withdrawn from POSIX, you may want to use mailx for portable applications. The ability to write directly to a file is an extension to POSIX.
Limits
Any individual line is limited to LINE_MAX bytes; of course, transport mechanisms between systems may impose shorter limits.
Related information
mailx, uudecode, uuencode