mail(1) mail(1)
NAME
mail - send or read mail
SYNOPSIS
mail [-tw] [-m messagetype] [--] recipient ... Format 1
mail [-ehpPqr] [-f file] Format 2
mail -F recipient ... Format 3
mail -T mailsurrfilerecipient ... Format 4
mail [-xdebuglevel] [othermailoptions ...] recipient ... Format 5
DESCRIPTION
This description is divided into the following sections:
- Introduction
- Description of individual formats
Format 1: Send mode
Functionality in send mode
Format 2: Read mode
mail commands in read mode
Functionality in read mode
Format 3: Forwarding mode
Functionality in forwarding mode
Formats 4 and 5: Debugging mode
- Exit status
- Files
- Examples
- See also
INTRODUCTION
mail enables you to send and receive electronic mail. If your computer
is linked to a network, mail can also be used to exchange messages
with users on remote systems.
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 mail.
Page 1 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
Messages are in the form of ASCII text. They have a message header
holding information needed for message forwarding; the nature of this
information is partly implementation-specific. The header is followed
by a blank line and then the text of the message.
mail allows you to
- send messages (send mode, Format 1)
- read messages (read mode, Format 2)
- forward messages (forwarding mode, Format 3)
- test the sending mechanism (debugging mode, Formats 4 and 5)
DESCRIPTION OF INDIVIDUAL FORMATS
Format 1: Send mode
mail [-tw] [-m messagetype] [--] recipient ...
-t Causes a To: recipient line to be added to the start of the mes-
sage header for each of the intended recipients.
-w Causes a letter to be sent to a remote recipient in the network
without waiting for completion of the remote transfer program.
-m messagetype
Causes a Message-Type: line to be added to the message header
with the value of messagetype. messagetype is any text string.
-- If recipient begins with a dash (-), the end of the command-line
options must be marked with with --.
recipient
is a valid login name on the local system, or a network address
if the computer on a network. You may specify more than one reci-
pient.
You will find information on network addressing in the next sec-
tion.
Functionality in send mode
The message to be sent is read from standard input. An EOF (<CTRL-D>)
or a line consisting of only a period (.) in the first column is
interpreted as the end of the input. The letter thus read is then sent
to the specified recipients, i.e. placed in their mailboxes. Each new
incoming message is inserted before any existing messages in a mail-
box.
Note: When reading from a file, mail does not treat a period on its
own at the start of a line as an end-of-text character.
Page 2 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
Components of a letter
A letter as it reaches its recipient is composed of
- some header lines
- a blank line, and
- the message body
The header lines section of the letter consists of the following ele-
ments:
- one or more UNIX postmarks of the form:
From sender dateandtime [remote from remotesystemname]
- one or more standardized message header lines of the form:
keywordname: [printable text]
Header lines may be continued on the following line if that line
starts with white space.
Keywords and the text that follows provide more detailed information
on incoming mail. Which keyword lines are included in the mail is
determined by the sending mode and the type of system from which the
message is sent.
Typical example of keywordname and printable text:
Received: from sender@system.domain
Date: date time
To: system!recipient
Content-Type: messagetype
Content-Length: messagelength
Undeliverable letters
If a letter is found to be undeliverable, it is returned to the sender
with appropriate diagnostics. If mail is interrupted by the SIGINT
signal (<DEL> key) during input, the entered text is saved in the file
dead.letter. The initial attempt to append to (or create) dead.letter
will be in the current directory. If this fails, dead.letter will be
appended to (or created in) the user's login directory. If the second
attempt also fails, no dead.letter processing will be done.
Page 3 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
Network addressing
You can also specify a network address as the recipient. The address-
ing method used will depend on the transport mechanisms available to
the local system. Consult your system administrator for details on
which addressing conventions are available on the local system. The
two most prevalent addressing schemes are:
- UUCP-style addressing, where addresses are specified as follows:
remotesystem!user
A series of system names separated by exclamation points can be
used to direct a letter through an extended network, such as
sysa!sysb!sysc!user.
- Domain-style addressing, where addresses are specified as follows:
user@[subdomain.]domain
Delivery notification
A number of different message headers can be added to those automati-
cally generated to determine the form in which notification of mail is
provided. These headers must be entered before the text of the message
with each keyword and its options in separate lines:
The following keywords and options are available:
Transport-Options: [option ...]
Default-Options: [option ...]
>To: recipient [option ...]
More than one option may be listed together without intervening white
space; but there must be slash (/) before each option. If contradic-
tory options are used, only the first option is recognized; the con-
flicting options that follow are ignored.
No options specified:
The default is /nodelivery/return.
The following options are available:
/delivery
Inform the sender that the message was successfully
delivered to the recipient's mailbox.
Page 4 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
/nodelivery
Do not inform the sender of successful deliveries.
/return
Inform the sender if the delivery of mail fails and return
the failed message to the sender.
/report
Same as /return except that the original message is not
returned.
/ignore
The sender is not informed of unsuccessful deliveries, and
the failed message is not returned.
recipient
Name of a recipient.
Format 2: Read mode
mail [-ehpPqr] [-f file]
No option specified:
mail checks the default mailbox /var/mail/$USER. If this file
contains messages, the last message received is printed on a
last-in, first-out basis. mail then issues a ? prompt and waits
for you to enter one of the commands described in the section on
mail commands in read mode.
-e mail 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.
-e must not be used together with -p.
-h (header) mail displays the contents of UNIX postmark lines for
all messages in the mailbox on a last-in, first-out basis. The
messages are numbered sequentially.
For information on UNIX postmarks, see Functionality in send
mode.
-p mail prints all mail messages in last-in, first-out order without
pausing between messages and then terminates.
-p must not be used together with -e.
-P mail prints all messages individually along with all header lines
in last-in, first-out order.
-q Causes mail to terminate on receiving the SIGINT signal (<DEL>
key).
Page 5 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
-q not specified:
The SIGINT signal interrupts only the message that is being
printed. The mail command p can be used to display the current
message again.
-r Displays messages in the order in which they were received, i.e.
in first-in, first-out order.
-r not specified:
Messages are displayed in last-in, first-out order.
-f mailfile
mail is to read messages from the designated mailfile.
-f mailfile not specified:
Messages are read from the default mailbox /var/mail/$USER.
Note: mail interprets the first lines of incoming mail as header
lines if they start with a string of non-blank characters
including a colon (:).
If you send mail which itself begins with a string of charac-
ters including a colon, you must insert a blank line before the
first line of text.
mail commands in read mode
mail displays a question mark as the input prompt for the commands
described below. Each command must be terminated with <RETURN>.
If you use one or more of the deletion commands d, dp, m, r, s, w or y
during a mail session and then undo the deletion with u and/or exit
the mail session with x, the files scheduled for deletion will be
preserved in /var/mail/$USER.
?
* Display an overview of available mail commands.
<RETURN>
+
n (next) Print next message.
- Print previous message.
number
Print message with specified message number.
# Print number of current message.
Page 6 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
!shell-command
Execute specified shellcommand.
<CTRL-D>
Causes mail to exit, leaving undeleted messages in the mailbox
(like q).
a (arrived) Print message that arrived during the current mail ses-
sion.
d
dp (delete/print) Delete message and print next.
dn Delete message number n. Do not print the next message.
dq (delete/quit) Delete message and quit mail.
h (header) Display a window of headers around current message.
hn Display a window of headers around message number n.
h a (header all) Display headers of all messages in the user's mail-
box.
h d (header/delete) Display headers of messages scheduled for dele-
tion.
m [recipient ...]
Mail the current message to the named recipient(s) and then
delete it.
recipient not specified:
Your own login name is assumed as the default recipient.
p Print current message again, overriding any indications of binary
(i.e. unprintable) content.
P (Print) Override default brief mode and print current message
again, displaying all header lines.
q Quit, leaving undeleted messages in the mailbox (same as
<CTRL-D>).
r [user ...]
Reply to the sender, and other user(s), then delete the message.
The reply is entered in the same manner as when sending mail.
user not specified:
The reply is sent to the sender only.
Page 7 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
s [file ...]
Save the message in the file named file and delete the message.
file is created in the current directory unless you specify an
absolute path name. If file already exists, the new message is
appended to it.
file not specified:
The default file $HOME/mbox is used.
u[n] Undelete message number n.
n not specified:
The last message read is undeleted.
w [file ...]
(write) Like s or y, except that header lines are not written to
the named file.
file not specified:
The default file $HOME/mbox is used.
x Exit mail, leaving all messages unchanged in the mailbox. In
other words, deleted messages are retained (see also <CTRL-D> and
q).
y [file ...]
(yank) Same as s.
Functionality in read mode
mail prints the most recent incoming message on the standard output.
Unless redefined with the -P option, the default mode for printing
messages is to print only those header lines of immediate interest.
These include the UNIX From and >From postmarks, the From:, Date:,
Subject:, and Content-Length: header lines, and any recipient header
lines such as To:, Cc:, or Bcc: (see also Functionality in send mode
and the mailx command).
After the header lines, mail displays the body of the message, pro-
vided it contains no unprintable characters. Otherwise, it will issue
a warning about the message having binary content and not display the
message itself.
Messages that take up more than one screen page can only be halted
with <CTRL-S> and restarted with <CTRL-Q>. You can also redirect the
output to a file for further processing, or use the command mailx,
which has a range of output control functions.
Page 8 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
Using mail commands
After printing the first message, mail displays a "?" and waits for
you to enter mail commands. Each command must be terminated with
<RETURN>.
If you use one or more of the deletion commands d, dp, m, r, s, w or y
during a mail session, the files scheduled for deletion will be
preserved in /var/mail/$USER if
- you undo the deletion with u during the session, and/or
- exit the session with x.
Note: If mail is invoked without the -q option, interrupts (i.e. the
SIGINT signal) will only interrupt the message being printed.
The current message can be printed again using the mail command
p in such cases.
If the message to be read contains unprintable characters, mail
will simply issue a warning about its binary contents. The p
command can be used to print this message as well.
Mailbox file permissions
The functionality of mail can be manipulated by changing the permis-
sions of the mailbox file with chmod. The default mode is 0660 (which
allows neither reading not writing). The mode of the file may be
changed to read-write (0666) or read-only (0664).
If the default mode 0660 is changed, the file will be preserved even
when empty to perpetuate the desired permissions. The system adminis-
trator may override this file preservation by using the
DELEMPTYMAILFILE keyword in the system file /etc/mail/mailcnfg. The
group ID of the mailbox file must be mail to allow new messages to be
delivered, and the mailbox file must be writable by the mail group.
Format 3: Forwarding mode
mail -F recipient ...
-F Causes all incoming mail to be forwarded to the listed reci-
pients, provided the mailbox is empty at the time mail is
invoked.
recipient
A list up to 1024 bytes long, in which individual users are named
as recipients and separated by either commas or white space. The
list should be enclosed in double quotes to ensure that it is
interpreted as a single operand of the -F option.
Page 9 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
Forwarding mode can be terminated by entering the null string
(mail -F "") as recipient.
If the first character of any recipient name is the pipe symbol,
the remainder of the line will be interpreted as a command to
which the current mail message is to be piped (see the next sec-
tion).
Functionality in forwarding mode
The -F option allows you to forward incoming mail to other users (or
to yourself on another computer). Before activating this mode, you
must first ensure that your mailbox is empty. When the command mail -F
recipient is given, mail enters the line Forward to recipient ... as
the first line in your mailbox and there after forwards all incoming
messages to the named recipients.
An Auto-Forwarded-From: ... line will be added to the header of each
forwarded message.
Executing commands in forwarding mode
If a recipient name in forwarding mode begins with the pipe symbol,
the remainder of the line is interpreted as a command to which the
current message is to be piped. The command, known as a Personal Sur-
rogate, will execute in the recipient's home directory. If the message
recipient cannot be found in the /etc/passwd file, the command will
not be executed, and a non-delivery notification will be returned to
the sender of the message. For example:
mail -F "|echo %R>/dev/tty016"
The specified recipient name in this case is |echo, which begins with
the pipe symbol. mail will therefore assume that a command is involved
and execute it using the parameters that follow (i.e. display the
return path to the message originator on terminal /dev/tty016).
It is also possible to forward mail to other recipients and pipe it to
a command at the same time, as in
mail -F "carol,joe,|myvacationprog %R"
After the pipe symbol, escaped double quotes (\") should be used to
cause strings with embedded whitespace to be considered as single
arguments to the command being executed. No shell syntax or metachar-
acters may be used unless the command specified is /usr/bin/sh. For
example,
mail -F "|/bin/sh -c \"shellcommandline\""
Certain keywords are allowed within the command being piped to and are
textually substituted for before the command line is executed:
Page 10 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
%R Return path to the message originator.
%c Value of the Content-Type: header line if present.
%S Value of the Subject: header line if present.
If the command being piped to exits with any non-zero value, mail
assumes that message delivery has failed and generates a non-delivery
notification to the message originator.
Forwarding loops
Message forwarding may result in a loop. Local loops (messages sent to
user1, which are forwarded to user2, and from there back to user1,
etc.) are detected immediately. Remote loops are not detected until a
built-in hop count limit of 20 is exceeded. In both cases a non-
delivery notification is sent to the message originator.
Mailbox file permissions
As a security precaution, chmod s+g is performed on /var/mail/$USER
whenever forwarding is activated, and chmod s-g is performed when for-
warding is removed. If the set-group-ID mode bit is not set when mail
attempts to forward an incoming message to a command, the operation
will fail and a non-delivery report with appropriate diagnostics will
be sent to the message originator.
To ensure that forwarding works properly, the mailbox file should have
the group ID of the mail group, and the group permission should be
read-write.
Additional functionality using notify and vacation
The two shell commands notify(1) and vacation(1) provide added func-
tionality. notify can be used for asynchronous notification of new
mail; vacation provides an auto-answer capability for messages when
the recipient will be unavailable for an extended period of time.
Formats 4 and 5: Debugging mode
mail -T mailsurrfile [--] recipient ...
mail [-xdebuglevel] [othermailoptions ...] [--] recipient ...
-T mailsurrfile
This option is useful for system administrators who need to
modify a mail surrogate file, which is a file containing surro-
gate commands for mail routing and transport
mailsurrfile can be any file name. If the null string is entered
instead (-T ""), mail will use the system file
/etc/mail/mailsurr.
Page 11 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
mail reads a message from standard input and traces the process-
ing of mailsurrfile on standard output without actually sending
the message.
recipient
Name(s) of one or more recipients on whom mailsurrfile is to be
tested.
-x mail creates a file named /tmp/MLDBGprocessid containing infor-
mation relating to how mail processed the current message.
The information provided is more detailed than that provided by
the -T option and is probably only useful to system administra-
tors.
debuglevel
Any positive or negative integer. The absolute value of
debuglevel controls the level of detail of the debug informa-
tion. If debuglevel is greater than zero, the debug information
will be retained only if mail encounters problems in processing
the message. If debuglevel is less than zero, all the informa-
tion that is relevant for processing will be retained. If
debuglevel is equal to zero, no debugging is performed.
debuglevel overrides the value of DEBUG in /etc/mail/mailcnfg.
othermailoptions
mail send options to be debugged.
-- If recipient begins with a dash (-), the end of the command-line
options must be marked with --.
recipient
Name(s) of one or more recipients on whom the sending mechanism
is to be tested.
EXIT STATUS
0 There were messages in the mailbox, and mail has been terminated
successfully. If no error occurred, the exit status for mailing
and debugging is equal to zero.
1 There were no messages in the mailbox or an error occurred during
initialization.
>1 An error occurred after initialization.
LOCALE
The LCMESSAGES environment variable governs the language in which
message texts are displayed. LCCTYPE governs character classes and
character conversion (shifting). LCCOLLATE governs the collating
sequence.
Page 12 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
The LCTIME environment variable governs the format of date and time
strings. If LCMESSAGES, LCCTYPE, LCCOLLATE or LCTIME is undefined
or is defined as the null string, it defaults to the value of LANG. If
LANG is likewise undefined or null, the system acts as if it were not
internationalized.
The LCALL environment variable governs the entire locale. LCALL
takes precedence over all the other environment variables which affect
internationalization.
If any of the locale variables has an invalid value, the system acts
as if none of the variables were set.
EXAMPLES
Example 1
Sending a message
User connie wishes to send a message to two other users: to annette on
the same host and to cindy on the remote host saturn. A To header line
(-t) is to be included for each of the recipients. In addition, the
sender is to be notified whether the message was successfully
delivered (Transport-Options).
$ mail -t annette saturn!cindy
or
$ mail -t annette cindy@saturn
Transport-Options: /delivery
Hi there!
Friday's meeting has had to be canceled, as the boss is
suffering from Repetitive Strain Injury brought on by
playing too much Tetris.
Bye for now, Connie
.
$
Example 2
Read and reply to a message
User cindy receives the message you have mail, so she has the new mes-
sage displayed. She then sends a reply to the sender and all other
recipients (r) and thus schedules the message for deletion. Since she
subsequently quits mail with q, the message is deleted.
$ mail
From connie Wed Jun 19 19:36:07 1991 remote from pluto.dept3
Received: from pluto.dept3 (pluto) by saturn.dept3.cortinus.de
at Wed, 19 Jun 91 19:36:05 +0100 (5.52.1/COR-1.1) with SMTP
From: connie@pluto.dept3
Date: Wed, 19 Jun 91 19:24 MDT
To: annette@pluto
Page 13 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
To: cindy@saturn
Content-Type: text
Content-Length: 199
Hi there!
Friday's meeting has had to be canceled, as the boss is
suffering from Repetitive Strain Injury brought on by
playing too much Tetris.
Bye for now, Connie
? r pluto!annette
mail pluto!connie pluto!annette
Get you facts straight!
It was quite definitely Lemmings, not Tetris.
Cindy
.
q
$
FILES
dead.letter
File that is used by mail to save messages that could not be
mailed, e.g. due to an error or an interrupt with <DEL> during
input. This file is created in the user's current or login direc-
tory and is generally appended to, not overwritten.
$HOME/mbox
Default file in which messages are saved by s, w and y commands.
/etc/passwd
System file containing all login names.
/etc/mail/mailsurr
System file used for mail system debugging.
/etc/mail/mailcnfg
File containing initialization information.
/tmp/ma*
Temporary file.
/tmp/MLDBG*
Debug trace file.
/var/mail/*.lock
Lock for mail directory.
/var/mail/:saved
Directory for holding temporary files to prevent loss of data in
the event of a system crash.
Page 14 Reliant UNIX 5.44 Printed 11/98
mail(1) mail(1)
/var/mail/$USER
Default mailbox (see $MAIL) for $USER, i.e. the mailfile in which
mail looks for incoming messages.
SEE ALSO
chmod(1), login(1), mailx(1), notify(1), sh(1), uuencode(1),
vacation(1), write(1), mailpipe(1M), mailcnfg(4), mailsurr(4).
Page 15 Reliant UNIX 5.44 Printed 11/98