MAIL(1)

NAME

mail, Mail - read or send mail messages

SYNOPSIS

Mail [ -deHinNUv ] [ -f [ filename | +folder ] ] [ -T file ] [ -u user ]

Mail [ -dFinUv ] [ -h number ] [ -r address ] [ -s subject ] recipient ...

/usr/ucb/mail ...

DESCRIPTION

mail is a comfortable, flexible, interactive program for composing, sending and receiving electronic messages. While reading messages, mail provides you with commands to browse, display, save, delete, and respond to messages. While sending mail, mail allows editing and reviewing of messages being composed, and the inclusion of text from files or other messages.

Incoming mail is stored in the system mailbox for each user. This is a file named after the user in /var/spool/mail . mail normally looks in this file for incoming messages, but you can use the MAIL environment variable to have it look in a different file. When you read a message, it is marked to be moved to a secondary file for storage. This secondary file, called the mbox , is normally the file mbox in your home directory. This file can also be changed by setting the MBOX environment variable. Messages remain in the mbox file until deliberately removed.

OPTIONS

If no recipient is specified, mail attempts to read messages from the system mailbox.

  • -d Turn on debugging output. (Neither particularly interesting nor recommended.)
  • -e Test for presence of mail. If there is no mail, mail prints nothing and exits (with a successful return code).
  • -F Record the message in a file named after the first recipient. Override the record variable, if set.
  • -H Print header summary only.
  • -i Ignore interrupts (as with the ignore variable).
  • -n Do not initialize from the system default Mail.rc file.
  • -N Do not print initial header summary.
  • -U Convert uucp style addresses to Internet standards. Overrides the conv environment variable.
  • -v Pass the -v flag to sendmail (8).
  • -f [ filename] Read messages from filename instead of system mailbox. If no filename is specified, the mbox is used.
  • -f + folder Use the file folder in the folder directory (same as the fold er command). The name of this directory is listed in the folder variable.
  • -h number The number of network hops made so far. This is provided for network software to avoid infinite delivery loops.
  • -r address Pass address to network delivery software. All tilde ( ~ ) commands are disabled.
  • -s subject Set the Subject header field to subject .
  • -T file Print the contents of the article-id fields of all messages that were read or deleted on file (for the use of network news programs if available).
  • -u user Read user 's system mailbox. This is only effective if user 's system mailbox is not read protected.

    USAGE

    Refer to for tutorial information about mail .

    Starting Mail

    As it starts, mail reads commands from a system-wide file ( /usr/lib/Mail.rc ) to initialize certain variables, then it reads from a private start-up file called the .mailrc file (it is normally the file .mailrc in your home directory, but can be changed by setting the MAILRC environment variable) for your personal commands and variable settings. Most mail commands are legal inside start-up files. The most common uses for this file are to set up initial display options and alias lists. The following commands are not legal in the start-up file: ! , C opy, e dit, fo llowup, F ollowup, ho ld, m ail, pre serve, r eply, R eply, replya ll, replys ender, sh ell, and v isual. Any errors in the start-up file cause the remaining lines in that file to be ignored.

    You can use the mail command to send a message directly by including names of recipients as arguments on the command line. When no recipients appear on the mail command line, it enters command mode, from which you can read messages sent to you. If you list no recipients and have no messages, mail prints the message: ` No mail for username ' and exits.

    When in command mode (while reading messages), you can send messages using the m ail command.

    Sending Mail

    While you are composing a message to send, mail is in input mode. If no subject is specified as an argument to the command a prompt for the subject is printed. After entering the subject line, mail enters input mode to accept the text of your message to send.

    As you type in the message, mail stores it in a temporary file. To review or modify the message, enter the appropriate tilde escapes , listed below, at the beginning of an input line.

    To indicate that the message is ready to send, type a dot (or EOF character, normally CTRL-D ) on a line by itself. mail submits the message to sendmail (8) for routing to each recipient .

    Recipients can be;

    If the name of the recipient begins with a pipe symbol ( | ), the remainder of the name is taken as a shell command to pipe the message through. This provides an automatic interface with any program that reads the standard input, such as lpr (1) to record outgoing mail on paper. An alias group is the name of a list of recipients that is set by the alias command, taken from the host's /etc/aliases file, or taken from the Network Information Service (NIS) aliases domain. See aliases (5) for more information about mail addresses and aliases.

    Tilde Escapes

    The following tilde escape commands can be used when composing messages to send. Each must appear at the beginning of an input line. The escape character (~), can be changed by setting a new value for the escape variable. The escape character can be entered as text by typing it twice. ~! [ shell-command ]
    Escape to the shell. If present, run shell-command .
  • ~. Simulate EOF (terminate message input). ~: mail-command
    ~_ mail-command
    Perform the indicated mail command. Valid only when sending a message while reading mail.
  • ~? Print a summary of tilde escapes.
  • ~A Insert the autograph string Sign into the message.
  • ~a Insert the autograph string sign into the message.
  • ~b name ... Add the name s to the blind carbon copy ( Bcc ) list. This is like the carbon copy ( Cc ) list, except that the names in the Bcc list are not shown in the header of the mail message.
  • ~c name ... Add the name s to the carbon copy ( Cc ) list.
  • ~d Read in the dead.letter file. The name of this file is listed in the variable DEAD .
  • ~e Invoke the editor to edit the message. The name of the editor is listed in the EDITOR variable. The default editor is ex (1). ~f [ message-list ]
    Forward the listed messages, or the current message being read. Valid only when sending a message while reading mail; the messages are inserted without alteration (as opposed to the ~m escape).
  • ~h Prompt for the message header lines: Subject , To , Cc , and Bcc . If the header line contains text, you can edit the text by backspacing over it and retyping.
  • ~i variable Insert the value of the named variable into the message. ~m [ message-list ]
    Insert text from the specified messages, or the current message, into the letter. Valid only when sending a message while reading mail; the text the message is shifted to the right, and the string contained in the indentprefix variable is inserted as the leftmost characters of each line. If indentprefix is not set, a TAB character is inserted into each line.
  • ~p Print the message being entered.
  • ~q Quit from input mode by simulating an interrupt. If the body of the message is not empty, the partial message is saved in the dead.letter file.
  • ~r filename
  • ~< filename
  • ~<! shell-command Read in text from the specified file or the standard output of the specified shell-command .
  • ~s subject Set the subject line to subject .
  • ~t name ... Add each name to the list of recipients.
  • ~v Invoke a visual editor to edit the message. The name of the editor is listed in the VISUAL variable. The default visual editor is vi (1).
  • ~w filename Write the message text onto the given file, without the header.
  • ~x Exit as with ~q but do not save the message in the dead.letter file.
  • ~| shell-command Pipe the body of the message through the given shell-command . If shell-command returns a successful exit status, the output of the command replaces the message.

    Reading Mail

    When you enter command mode in order to read your messages, mail displays a header summary of the first several messages, followed by a prompt for one of the commands listed below. The default prompt is the & (ampersand character).

    Message are listed and referred to by number. There is, at any time, a current message, which is marked by a > in the header summary. For commands that take an optional list of messages, if you omit a message number as an argument, the command applies to the current message.

    A message-list is a list of message specifications, separated by SPACE characters, which may include:

    Additional arguments are treated as strings whose usage depends on the command involved. Filenames, where expected, are expanded using the normal shell filename-substitution mechanism.

    Special characters, recognized by certain commands, are documented with those commands.

    Commands

    While in command mode, if you type in an empty command line (a RETURN or NEWLINE only), the p rint command is assumed. The following is a complete list of mail commands:
  • ! shell-command Escape to the shell. The name of the shell to use is listed in the SHELL variable.
  • # arguments Null command. This may be used as if it were a comment in .mailrc files, but note that it must be separated from its arguments (commentary) by white space.
  • = Print the current message number.
  • ? Print a summary of commands. a lias [ alias recipient ...]
    g roup [ alias recipient ...]
    Declare an alias for the given list of recipients. The list will be substituted when the alias is used as a recipient while sending mail. When put in the .mailrc file, this command provides you with a record of the alias. With no arguments, the command displays the list of defined aliases.
  • alt ernates name ... Declare a list of alternate names for your login. When responding to a message, these names are removed from the list of recipients for the response. With no arguments, alt ernates prints the current list of alternate names. cd [ directory ]
  • ch dir [directory] Change directory. If directory is not specified, $HOME is used. c opy [ message-list ] [ filename ]
    Copy messages to the file without marking the messages as saved. Otherwise equivalent to the s ave command.
  • C opy [message-list] Save the specified messages in a file whose name is derived from the author of the message to be saved, without marking the messages as saved. Otherwise equivalent to the S ave command.
  • d elete [message-list] Delete messages from the system mailbox. If the variable autoprint is set, print the message following the last message deleted. di scard [ header-field ...]
    ig nore [ header-field ...]
    Suppress printing of the specified header fields when displaying messages on the screen, such as Status and Received. The fields are included when the message is saved unless the variable alwaysignore is set. The P rint and T ype commands display all header fields, ignored or not. dp [ message-list ]
    dt [message-list]
    Delete the specified messages from the system mailbox, and print the message after the last one deleted. Equivalent to a d elete command followed by a p rint command.
  • ec ho [string ...] Echo the given strings (like echo (1V)).
  • e dit [message-list] Edit the given messages. The messages are placed in a temporary file and the EDITOR variable is used to get the name of the editor. The default editor is ex (1).
  • ex it
  • x it Exit from mail without changing the system mailbox. No messages are saved in the mbox (see also q uit). fi le [ filename ]
  • fold "er [filename] Quit from the current mailbox file and read in the named mailbox file. Several special characters are recognized when used as file names:

    To forward a specific message, include it in a message to the desired recipients with the ~f or ~m tilde escapes. To forward mail automatically, add a comma-separated list of addresses for additional recipients to the .forward file in your home directory. This is different from the format of the alias command, which takes a space-separated list instead. Note: forwarding addresses must be valid (as described in aliases (5)), or the messages will bounce. You cannot, for instance, reroute your mail to a new host by forwarding it to your new address if it is not yet listed in the NIS aliases domain.

    Variables

    The behavior of mail is governed by a set of predefined variables that are set and cleared using the se t and uns et commands.

    Environment Variables

    Values for the following variables are read in automatically from the environment; they cannot be altered from within mail : HOME = directory
    The user's home directory. MAIL = filename
    The name of the initial mailbox file to read (in lieu of the standard system mailbox). The default is /var/spool/mail/username. MAILRC = filename
    The name of the personal start-up file. The default is $HOME/.mailrc .

    Mail Variables

    The following variables can be initialized within the .mailrc file, or set and altered interactively using the se t command. They can also be imported from the environment (in which case their values cannot be changed within mail ). The uns et command clears variables. The set command can also be used to clear a variable by prefixing the word no to the name of the variable to clear.

    Variables for which values are normally supplied are indicated with an equal-sign ( = ). The equal-sign is required by the se t command, and there can be no spaces between the variable-name, equal-sign, and value, using set to assign a value.

  • allnet All network names whose last component (login name) match are treated as identical. This causes the message list specifications to behave similarly. Default is noallnet . See also the alt ernates command and the metoo variable.
  • alwaysignore Ignore header fields with ig nore everywhere, not just during p rint or t ype. Affects the s ave, S ave, c opy, C opy, to p, pi pe, and w rite commands, and the ~m and ~f tilde escapes.
  • append Upon termination, append messages to the end of the mbox file instead of prepending them. Default is noappend but append is set in the global start-up file (which can be suppressed with the -n command line option).
  • askcc Prompt for the Cc list after message is entered. Default is noaskcc .
  • asksub Prompt for subject if it is not specified on the command line with the -s option. Enabled by default.
  • autoprint Enable automatic printing of messages after d elete and u ndelete commands. Default is noautoprint .
  • bang Enable the special-casing of exclamation points (!) in shell escape command lines as in vi (1). Default is nobang .
  • cmd= shell-command Set the default command for the pi pe command. No default value.
  • conv= conversion Convert uucp addresses to the address style specified by conversion , which can be either:

    mail is found in /usr/ucb/Mail , as a link to /usr/ucb/mail . If you wish to use the original (version 7) UNIX mail program, you can find it in /usr/bin/mail . Its man page is named bin-mail (1).

    BUGS

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

    Internal variables imported from the execution environment cannot be uns et.

    Replies do not always generate correct return addresses. Try resending the errant reply with onehop set.

    mail does not lock your record file. So, if you use a record file and send two or more messages simultaneously, lines from the messages may be interleaved in the record file.

    The format for the alias command is a space-separated list of recipients, while the format for an alias in either the .forward or /etc/aliases is a comma-separated list.

    NOTES

    The Network Information Service (NIS) was formerly known as Sun Yellow Pages (YP). The functionality of the two remains the same; only the name has changed.