2.4 mail — Send and Receive Mail

Mail is an enhanced version of standard /bin/mail program. As well as its predecessor, it can be used either in sending mode or in reading mode. Mail enters sending mode when one or more email addresses were specified in this command line. In this mode the program waits until user finishes composing the message, then attempts to send it to the specified addresses and exits. See Composing Mail, for a detailed description of this behavior.

If the command line contained no email addresses, mail switches to reading mode. In this mode it allows to read and manipulate the contents of the user system mailbox. The ‘--file’ (‘-f’) command line option allows to specify another mailbox name. For more detail, see Reading Mail.

In contrast to other GNU Mailutils programs, mail does not use the Mailutils configuration file. Instead, it uses the traditional ‘mailrc’-style configuration. See section Personal and System-wide Configuration Files, for a detailed description of its format.

2.4.1 Invoking mail

General usage of mail program is:

 
      mail [option...] [address...]

If [address...] part is present, mail switches to mail sending mode, otherwise it operates in mail reading mode.

The program uses following option groups: .

Mail understands following command line options:

-e
--exist

Return true if the mailbox contains some messages. Return false otherwise. This is useful for writing shell scripts.

-E command
--exec=command

Execute command before opening the mailbox. Any number of ‘--exec’ options can be given. The commands will be executed after sourcing configuration files (see section Personal and System-wide Configuration Files), but before opening the mailbox.

-f
--file

Operate on the mailbox given by the first non-optional command line argument. If there is no such argument, read messages from the user's ‘mbox’ file. See section Reading Mail, for more details about using this option.

-F
--byname

Record outgoing messages in a file named after the first recipient. The name is the login-name portion of the address found first on the ‘To:’ line in the mail header. This option sets the ‘byname’ variable, which see (see byname).

-H
--headers

Print header summary to stdout and exit.

-i
--ignore

Ignore interrupts.

-m path
--mail-spool=path

Set path to the mailspool directory

-n
--norc

Do not read the system-wide mailrc file. See section Personal and System-wide Configuration Files.

-N
--nosum

Do not display initial header summary.

-p
--print
-r
--read

Print all mail to standard output. It is equivalent to issuing following commands after starting ‘mail -N’:

 
print *
quit
-q
--quit

Cause interrupts to terminate program.

-s subj
--subject=subj

Send a message with a Subject of subj. Valid only in sending mode.

-t
--to

Switch to sending mode.

-u user
--user=user

Operate on user's mailbox. This is equivalent to:

 
mail -f/spool_path/user

with spool_path being the full path to your mailspool directory
(‘/var/spool/mail’ or ‘/var/mail’ on most systems).

-?
--help

Display a help message.

--usage

Display a short usage summary.

-V
--version

Print program version and exit.

2.4.2 How to Specify Message Sets

Many mail commands such as print and delete can be given a message list to operate upon. Wherever the message list is omitted, the command operates on the current message.

The message list in its simplest form is one of:

.

Selects current message. It is equivalent to empty message list.

*

Selects all messages in the mailbox.

^

Selects first non-deleted message.

$

Selects last non-deleted message.

In its complex form, the message list is a comma or whitespace-separated list of message specifiers. A message specifier is one of

Message Number

This specifier addresses the message with the given ordinal number in the mailbox.

Message range

Message range is specified as two message numbers separated by a dash. It selects all messages with the number lying within that range.

Attribute specifier

An Attribute specifier is a colon followed by a single letter. The Attribute specifier addresses all messages in the mailbox that have the given attribute. These are the valid attribute specifiers:

:d

Selects all deleted messages.

:n

Selects all recent messages, i.e. the messages that have not been neither read not seen so far.

:o

Selects all messages that have been seen.

:r

Selects all messages that have been read.

:u

Selects all messages that have not been read.

:t

Selects all tagged messages.

:T

Selects all untagged messages.

Header match

The header match is a string in the form:

 
[header:]/string/

It selects all messages that contain header field header matching given regexp. If the variable regexp is set, the string is assumed to be a POSIX regexp. Otherwise, a header is considered to match string if the latter constitutes a substring of the former (comparison is case-insensitive).

If header: part is omitted, it is assumed to be ‘Subject:’.

Message body match

The message body match is a string in the form:

 
:/string/

It selects all messages whose body matches the string. The matching rules are the same as described under “Header match”.

A message specifier can be followed by message part specifier, enclosed in a pair of brackets. A message part specifier controls which part of a message should be operated upon. It is meaningful only for multipart messages. A message part specifier is a comma or whitespace - separated list of part numbers or ranges. Each part number can in turn be message part specifier, thus allowing for operating upon multiply-encoded messages.

The following are the examples of valid message lists:

2.4.3 Composing Mail

You can compose the message by simply typing the contents of it, line by line. But usually this is not enough, you would need to edit your text, to quote some messages, etc. Mail provides these capabilities through compose escapes. The compose escapes are single-character commands, preceded by special escape character, which defaults to ‘~’. The combination escape character + command is recognized as a compose escape only if it occurs at the beginning of a line. If the escape character must appear at the beginning of a line, enter it twice. The actual escape character may be changed by setting the value of escape mail variable (see section How to Alter the Behavior of mail).

Quitting Compose Mode

There are several commands allowing you to quit the compose mode.

Typing the end-of-file character (‘C-D’) on a line alone finishes compose mode and sends the message to its destination. The ‘C-D’ character looses its special meaning if ignoreeof mail variable is set.

If mail variable dot is set, typing dot (‘.’) on a line alone achieves the same effect as ‘C-D’ above.

Finally, using ‘~.’ escape always quits compose mode and sends out the composed message.

To abort composing of a message without sending it, type interrupt character (by default, ‘C-C’) twice. This behavior is disabled when mail variable ignore is set. In this case, you can use ‘~x’ escape to achieve the same effect.

Getting Help on Compose Escapes: ~?

The ‘~?’ escape prints on screen a brief summary of the available compose escapes. Please note, that ‘~h’ escape prompts for changing the header values, and does not give help.

Editing the Message: ~e and ~v

If you are not satisfied with the message as it is, you can edit it using a text editor specified either by EDITOR or by VISUAL environment variables. The ‘~e’ uses the former, and ‘~v’ uses the latter.

By default both escapes allow you to edit only the body of the message. However, if the editheaders variable is set, mail will load into the editor the complete text of the message with headers included, thus allowing you to change the headers as well.

Modifying the Headers: ~h, ~t, ~c, ~b, ~s

To add new addresses to the list of message recipients, use ‘~t’ command, e.g.:

 
~t name1@domain.net name2

To add addresses to Cc or Bcc, use ‘~c’ or ‘~b’ escapes respectively.

To change the Subject header, use ‘~s’ escape, e.g.:

 
~s "Re: your message"

Finally, to edit all headers, type ‘~h’ escape. This will present you with the values of To, Cc, Bcc, and Subject headers allowing to edit them with normal text editing commands.

Enclosing Another Message: ~m and ~M

If you are sending mail from within mail command mode, you can enclose the contents of any message sent to you by using ‘~m’ or ‘~M’ commands. Typing ‘~m’ alone will enclose the contents of the current message, typing ‘~m 12’ will enclose the contents of message #12 and so on.

The ‘~m’ uses retained and ignored lists when enclosing headers, the ‘~M’ encloses all header fields.

In both cases, the contents of indentprefix mail variable is prepended to each line enclosed.

Adding a File to the Message: ~r and ~d

To append the contents of file filename to the message, type

 
~r filename

or

 
~< filename

The ‘~d’ escape is a shorthand for

 
~r dead.letter

Printing And Saving the Message

The ‘~p’ escape types the contents of the message entered so far, including headers, on your terminal. You can save the message to an arbitrary file using ‘~w’ escape. It takes the filename as its argument.

Signing the Message: ~a and ~A

To save you the effort of typing your signature at the end of each message, you can use ‘~a’ or ‘~A’ escapes. If your signature occupies one line only, save it to the variable sign and use ‘~a’ escape to insert it. Otherwise, if it is longer than one line, save it to a file, store the name of this file in the variable Sign, and use ‘~A’ escape to insert it into the message.

Printing Another Message: ~f and ~F

Sometimes it is necessary to view the contents of another message, while composing. These two escapes allow it. Both take the message list as their argument. If they are used without argument, the contents of the current message is printed. The difference between ‘~f’ and ‘~F’ is that the former uses ignored and retained lists to select headers to be displayed, whereas the latter prints all headers.

Inserting Value of a Mail Variable: ~i

The ‘~i’ escape enters the value of the named mail variable into the body of the message being composed.

Executing Other Mail Commands: ~: and ~-

You can execute a mail command from within compose mode using ‘~:’ or ‘~-’ escapes. For example, typing

 
~: from :t

will display the from lines of all tagged messages. Note, that executing mail-sending commands from within the compose mode is not allowed. An attempt to execute such a command will result in diagnostic message “Command not allowed in an escape sequence” being displayed. Also, when starting compose mode immediately from the shell (e.g. running ‘mail address@domain’), most mail commands are meaningless, since there is no mailbox to operate upon. In this case, the only commands that can reasonably be used are: alias, unalias, alternate, set, and unset.

Executing Shell Commands: ~! and ~|

The ‘~!’ escape executes specified command and returns you to mail compose mode without altering your message. When used without arguments, it starts your login shell. The ‘~|’ escape pipes the message composed so far through the given shell command and replaces the message with the output the command produced. If the command produced no output, mail assumes that something went wrong and retains the old contents of your message.

2.4.4 Reading Mail

To read messages from a given mailbox, use one of the following ways of invoking mail:

mail

To read messages from your system mailbox.

mail -f
mail --file

To read messages from your mailbox (‘$HOME/mbox’). If the ‘--user’ option (see below) is also given, read messages from that user's ‘mbox’.

mail -f path_to_mailbox
mail --file path_to_mailbox

To read messages from the specified mailbox.

mail -u user
mail --user=user

To read messages from the system mailbox belonging to user.

Please note, that usual mailbox permissions won't allow you to use the last variant of invocation, unless you are a super-user. Similarly, the last but one variant is also greatly affected by the permissions the target mailbox has.

Notice that path_to_mailbox is not an argument to ‘--file’ (‘-f’) option, but rather the first non-optional argument on the command line. Therefore, the following three invocations are equivalent:

 
$ mail -fin mymbox
$ mail -f mymbox -in
$ mail --file -in mymbox
$ mail --file -i mymbox -n

Additionally, for conformance to the GNU standards, the following form is also accepted:

 
$ mail --file=mymbox -i -n

Unless you have started mail with ‘--norc’ command line option, it will read the contents of the system-wide configuration file. Then it reads the contents of user configuration file, if any. For detailed description of these files, see Personal and System-wide Configuration Files. After this initial setup, mail displays the first page of header lines and enters interactive mode. In interactive mode, mail displays its prompt (‘?’, if not set otherwise) and executes the commands the user enters.

Quitting the Program

Following commands quit the program:

quit

Terminates the session. If mail was operating upon user's system mailbox, then all undeleted and unsaved messages that have been read and are not marked with hold flag are saved to the user's mbox file (‘$HOME/mbox’). The messages, marked with delete are removed. The program exits to the Shell, unless saving the mailbox fails, in which case user can escape with the exit command.

exit
ex
xit

Program exits to the Shell without modifying the mailbox it operates upon.

Typing EOF (‘C-D’) alone is equivalent to ‘quit’.

Obtaining Online Help

Following commands can be used during the session to request online help:

help [command]
hel [command]
? [command]

Display detailed command synopsis. If no command is given, help for all available commands is displayed.

list
*

Print a list of available commands.

version
ve

Display program version.

warranty
wa

Display program warranty statement.

Moving Within a Mailbox

^

Move to the first undeleted message.

$

Move to the last undeleted message.

next
n

Move to the next message.

previous
prev

Move to the previous message.

Changing Mailbox/Directory

cd [dir]
chdir [dir]
ch [dir]

Change to the specified directory. If dir is omitted, $HOME is assumed.

file [mailbox]
fi [mailbox]
folder [mailbox]
fold [mailbox]

Read in the contents of the specified mailbox. The current mailbox is updated as if quit command has been issued. If mailbox is omitted, the command prints the current mailbox name followed by the summary information regarding it, e.g.:

 
& fold
"/var/spool/mail/gray": 23 messages 22 unread

Controlling Header Display

To control which headers in the message should be displayed, mail keeps two lists: a retained header list and an ignored header list. If retained header list is not empty, only the header fields listed in it are displayed when printing the message. Otherwise, if ignored header list is not empty, only the headers not listed in this list are displayed. The uppercase variants of message-displaying commands can be used to print all the headers.

The following commands modify and display the contents of both lists.

discard [header-field-list]
di [header-field-list]
ignore [header-field-list]
ig [header-field-list]

Add header-field-list to the ignored list. When used without arguments, this command prints the contents of ignored list.

retain [header-field-list]
ret [header-field-list]

Add header-field-list to the retained list. When used without arguments, this command prints the contents of retained list.

Displaying Information

=

Displays the current message number.

headers [msglist]
h [msglist]

Lists the current pageful of headers.

from [msglist]
f [msglist]

Lists the contents of ‘From’ headers for a given set of messages.

z [arg]

Presents message headers in pagefuls as described for headers command. When arg is ‘.’, it is generally equivalent to headers. When arg is omitted or is ‘+’, the next pageful of headers is displayed. If arg is ‘-’, the previous pageful of headers is displayed. The latter two forms of z command may also take a numerical argument meaning the number of pages to skip before displaying the headers. For example:

 
& z +2

will skip two pages of messages before displaying the header summary.

size [msglist]
si [msglist]

Lists the message number and message size in bytes for each message in msglist.

folders

Displays the value of folder variable.

summary
su

Displays current mailbox summary. E.g.:

 
& summary
"/var/spool/mail/gray": 23 messages 22 unread

Displaying Messages

print [msglist]
p [msglist]
type [msglist]
t [msglist]

Prints out the messages from msglist. The variable crt determines the minimum number of lines the body of the message must contain in order to be piped through pager command specified by environment variable PAGER. If crt is set to a numeric value, this value is taken as the minimum number of lines. Otherwise, if crt is set without a value then the height of the terminal screen is used to compute the threshold. The number of lines on screen is controlled by screen variable.

Print [msglist]
P [msglist]
Type [msglist]
T [msglist]

Like print but also prints out ignored header fields.

decode [msglist]
dec [msglist]

Print a multipart message. The decode command decodes and prints out specified message parts. E.g.

 
& decode 15[2]
+---------------------------------------
| Message=15[2]
| Type=message/delivery-status
| encoding=7bit
+---------------------------------------
Content-Type: message/delivery-status
...
top [msglist]
to [msglist]

Prints the top few lines of each message in msglist. The number of lines printed is controlled by the variable toplines and defaults to five.

pipe [msglist] [shell-command]
| [msglist] [shell-command]

Pipe the contents of specified messages through shell-command. If shell-command is empty but the string variable cmd is set, the value of this variable is used as a command name.

struct [msglist]

Prints the MIME structure of each message from msglist. Empty msglist means current message.

Example:

 
& struct 2
2      multipart/mixed            14k
2[1]   text/plain                 296
2[2]   application/octet-stream    5k
2[3]   text/x-diff                31k

Marking Messages

tag [msglist]
ta [msglist]

Tag messages. The tagged messages can be referred to in message list using ‘:t’ notation.

untag [msglist]
unt [msglist]

Clear tags from specified messages. To untag all messages tagged so far type

 
& untag :t
hold [msglist]
ho [msglist]
preserve [msglist]
pre [msglist]

Marks each message to be held in user's system mailbox. This command does not override the effect of delete command.

Disposing of Messages

delete [msglist]
d [msglist]

Mark messages as deleted. Upon exiting with quit command these messages will be deleted from the mailbox. Until the end of current session the deleted messages can be referred to in message lists using :d notation.

undelete [msglist]
u [msglist]

Clear delete mark from the specified messages.

dp [msglist]
dt [msglist]

Deletes the current message and prints the next message. If msglist is specified, deletes all messages from the list and prints the message, immediately following last deleted one.

Saving Messages

save [[msglist] file]
s [[msglist] file]

Takes a message list and a file name and appends each message in turn to the end of the file. The name of file and number of characters appended to it is echoed on the terminal. Each saved message is marked for deletion as if with delete command, unless the variable keepsave is set.

Save [msglist]
S [msglist]

Like save, but the file to append messages to is named after the sender of the first message in msglist. For example:

 
& from 14 15
 U  14 smith@noldor.org Fri Jun 30 18:11  14/358   The Save c
 U  15 gray@noldor.org  Fri Jun 30 18:30  8/245    Re: The Sa
& Save 14 15
"smith" 22/603

i.e., 22 lines (603 characters) have been appended to the file “smith”. If the file does not exist, it is created.

write [[msglist] file]
w [[msglist] file]

Similar to save, except that only message body (without the header) is saved.

Write [msglist]
W [msglist]

Similar to Save, except that only message body (without the header) is saved.

mbox [msglist]
mb [msglist]
touch [msglist]
tou [msglist]

Mark list of messages to be saved in the user's mailbox (‘$HOME/mbox’) upon exiting via quit command. This is the default action for all read messages, unless you have variable hold set.

copy [[msglist] file]
c [[msglist] file]

Similar to save, except that saved messages are not marked for deletion.

Copy [msglist]
C [msglist]

Similar to Save, except that saved messages are not marked for deletion.

Editing Messages

These command allow to edit messages in a mailbox. Please note, that modified messages currently do not replace original ones. i.e. you have to save them explicitly using your editor's save command if you do not want the effects of your editing to be lost.

edit [msglist]
e [msglist]

Edits each message in msglist with the editor, specified in EDITOR environment variable.

visual [msglist]
v [msglist]

Edits each message in msglist with the editor, specified in VISUAL environment variable.

Aliasing

alias [alias [address...]]
a [alias [address...]]
group [alias [address...]]
g [alias [address...]]

With no arguments, prints out all currently-defined aliases. With one argument, prints out that alias. With more than one argument, creates a new alias or changes an old one.

unalias [alias...]
una [alias...]

Takes a list of names defined by alias commands and discards the remembered groups of users. The alias names no longer have any significance.

alternates name...
alt name...

The alternates command is useful if you have accounts on several machines. It can be used to inform mail that the listed addresses are really you. When you reply to messages, mail will not send a copy of the message to any of the addresses listed on the alternates list. If the alternates command is given with no argument, the current set of alternate names is displayed.

Replying

mail [address...]
m [address...]

Switches to compose mode. After composing the message, sends messages to the specified addresses.

reply [msglist]
respond [msglist]
r [msglist]

For each message in msglist, switches to compose mode and sends the composed message to the sender and all recipients of the message.

Reply [msglist]
Respond [msglist]
R [msglist]

Like reply, except that the composed message is sent only to originators of the specified messages.

Notice, that setting mail variable flipr (see section How to Alter the Behavior of mail) swaps the meanings of the two above commands, so that reply sends the message to the sender and all recipients of the message, whereas Reply sends it to originators only.

followup [msglist]
fo [msglist]

Switches to compose mode. After composing, sends the message to the originators and recipients of all messages in msglist.

Followup [msglist]
F [msglist]

Similar to followup, but reply message is sent only to originators of messages in msglist.

To determine the sender of the message mail uses the list of sender fields (see Controlling Sender Fields). The first field from this list is looked up in message headers. If it is found and contains a valid email address, this address is used as the sender address. If not, the second field is searched and so on. This process continues until a field is found in the headers, or the sender field list is exhausted, whichever happens first.

If the previous step did not determine the sender address, the address from SMTP envelope is used.

Let's illustrate this. Suppose your mailbox contains the following:

 
 U  1 block@helsingor.org  Fri Jun 30 18:30  8/245    Re: The Sa
& Print 1
From: Antonius Block <block@helsingor.org>
To: Smeden Plog <plog@helsingor.org>
Date: Tue, 27 Apr 2004 13:23:41 +0300
Reply-To: <root@helsingor.org>
Subject: News

Hi

Now, you issue the following commands:

 
& sender mail-followup-to reply-to from
& reply
To: <root@helsingor.org>
Subject: Re: News

As you see, the value of Reply-To field was taken as the sender address.

Now, let's try the following command sequence:

 
# Clear the sender list
& nosender
# Set new sender list
& sender From

Now, the From address will be taken:

 
& reply
To: Antonius Block <block@helsingor.org>
Subject: Re: News

Controlling Sender Fields

Commands sender and nosender are used to manipulate the contents of the sender field list.

If the command sender is used without arguments, it displays the contents of the sender field list. If arguments are given, each argument is appended to the sender field list. For example:

 
& sender
Sender address is obtained from the envelope
& sender mail-followup-to reply-to
& sender
mail-followup-to
reply-to
& sender from
& sender
mail-followup-to
reply-to
from

Command nosender is used to remove items from the sender field list:

 
& sender
mail-followup-to
reply-to
from
& nosender reply-to
& sender
mail-followup-to
from

When used without arguments, this command clears the list:

 
& nosender
Sender address is obtained from the envelope

Incorporating New Mail

The incorporate (inc) command incorporates newly arrived messages to the displayed list of messages. This is done automatically before returning to mail command prompt if the variable autoinc is set.

Shell Escapes

To run arbitrary shell command from mail command prompt, use shell (sh) command. If no arguments are specified, the command starts the user login shell. Otherwise, it uses its first argument as a file name to execute and all subsequent arguments are passed as positional parameters to this command. The shell command can also be spelled as !.

2.4.5 Scripting

Comments

The ‘#’ character introduces an end-of-line comment. All characters until and including the end of line are ignored.

Displaying Arbitrary Text

The ‘echo’ (‘ec’) command prints its arguments to stdout.

Sourcing External Command Files

The command ‘source filename’ reads commands from the named file. Its minimal abbreviation is ‘so’.

Setting and Unsetting the Variables

The mail variables are set using ‘set’ (‘se’) command. The command takes a list of assignments. The syntax of an assignment is

name=string

Assign a string value to the variable. If string contains whitespace characters it must be enclosed in a pair of double-quote characters (‘"’)

name=number

Assign a numeric value to the variable.

name

Assign boolean True value.

noname

Assign boolean False value.

Example:

 
& set askcc nocrt indentprefix="> "

This statement sets askcc to True, crt to False, and indentprefix to “> ”.

To unset mail variables use ‘unset’(‘uns’) command. The command takes a list of variable names to unset.

Example: To undo the effect of the previous example, do:

 
& unset askcc crt indentprefix

When used without arguments, both set or unset list all currently defined variables. The form of this listing is controlled by variable-pretty-print (varpp) variable. If it is set, a description precedes each variable, e.g.:

 
# prompt user for subject before composing the message
ask
# prompt user for cc before composing the message
askcc
# output character set for decoded header fields
charset="auto"
# number of columns on terminal screen
columns=80

If variable-pretty-print is not set, only the settings are shown, e.g.:

 
ask
askcc
charset="auto"
columns=80

A special command is provided to list all internal mail variables:

 
variable [names...]

If used without arguments, it prints all known internal variables. If arguments are given, it displays only those internal variables that are listed in command line. For each variable, this command prints its name, data type, current value and a short description. For example:

 
& variable ask datefield
ask, asksub
Type: boolean
Current value: yes
prompt user for subject before composing the message

datefield
Type: boolean
Current value: [not set]
get date from the `Date:' header, instead of the envelope

Setting and Unsetting Shell Environment Variables

Shell environment may be modified using ‘setenv’ (‘sete’) command. The command takes a list of assignments. The syntax of an assignment is:

name=value

If variable name does not already exist in the environment, then it is added to the environment with the value value. If name does exist, then its value in the environment is changed to value.

name

Delete the variable name from the environment (“unset” it).

Conditional Statements

The conditional statement allows to execute a set of mail commands depending on the mode the mail program is in. The conditional statement is:

 
if cond
...
else
...
endif

where ‘...’ represents the set of commands to be executed in each branch of the statement. cond can be one of the following:

s

True if mail is operating in mail sending mode.

r

True if mail is operating in mail reading mode.

t

True if stdout is a terminal device (as opposed to a regular file).

The conditional statements can be nested to arbitrary depth. The minimal abbreviations for ‘if’, ‘else’ and ‘endif’ commands are ‘i’, ‘el’ and ‘en’.

Example:

 
if t
set crt prompt="& "
else
unset prompt
endif
if s
alt gray@farlep.net gray@mirddin.farlep.net
set

2.4.6 How to Alter the Behavior of mail

Following variables control the behavior of GNU mail:

append

Type: Boolean, Read-Only
Default: True

Messages saved in mbox are appended to the end rather than prepended. This is the default and cannot be changed. This variable exists only for compatibility with other mailx implementations.

appenddeadletter

Type: Boolean.
Default: False.

If this variable is True, the contents of canceled letter is appended to the user's ‘dead.letter’ file. Otherwise it overwrites its contents.

askbcc

Type: Boolean.
Default: False.

When set to True the user will be prompted to enter Bcc field before composing the message.

askcc

Type: Boolean.
Default: True.

When set to True the user will be prompted to enter Cc field before composing the message.

asksub

Type: Boolean.
Default: True in interactive mode, False otherwise.

When set to True the user will be prompted to enter Subject field before composing the message.

autoinc

Type: Boolean.
Default: True.

Automatically incorporate newly arrived messages.

autoprint

Type: Boolean.
Default: False.

Causes the delete command to behave like dp - thus, after deleting a message, the next one will be typed automatically.

bang

Type: Boolean.
Default: False.

When set, every occurrence of ! in arguments to ! command is replaced with the last executed command.

byname

Type: Boolean
Default: Unset

Record outgoing messages in a file named after the first recipient. The name is the login-name portion of the address found first on the ‘To:’ line in the mail header. This variable overrides the ‘record’ variable.

It is set by the ‘--byname’ (‘-F’) command line option.

datefield

Type: Boolean.
Default: False.

By default the date in a header summary is taken from the SMTP envelope of the message. Setting this variable tells mail to use the date from Date: header field, converted to local time. Notice, that for messages lacking this field mail will fall back to using SMTP envelope.

See fromfield.

charset

Type: string
Default: ‘auto

The value of this variable controls the output character set for the header fields encoding using RFC 2047. If the variable is unset, no decoding is performed and the fields are printed as they are. If the variable is set to ‘auto’, mail tries to deduce the name of the character set from the value of LC_ALL environment variable. Otherwise, its value is taken as the name of the charset.

cmd

Type: String.
Default: Unset.

Contains default shell command for pipe.

columns

Type: Numeric.
Default: Detected at startup by querying the terminal device. If this fails, the value of environment variable COLUMNS is used.

This variable contains the number of columns on terminal screen.

crt

Type: Boolean or Numeric
Default: True in interactive mode, False otherwise.

The variable crt determines the minimum number of lines the body of the message must contain in order to be piped through pager command specified by environment variable PAGER. If crt is set to a numeric value, this value is taken as the threshold. Otherwise, if crt is set without a value, then the height of the terminal screen is used to compute the threshold. The number of lines on screen is controlled by screen variable.

debug

Type: String to boolean
Default: Not set

Sets mailutils debug level. If set to string, the value must be a valid Mailutils debugging specification. See section Debug Statement, for a description.

If unset (i.e. set nodebug), clears and disables all debugging information. If set to ‘true’ (i.e. set debug), sets maximum debugging (‘<trace7’) on mailbox and its underlying objects.

decode-fallback

Type: String.
Default: ‘none’.

This variable controls the way to represent characters that cannot be rendered using current character set. It can have three values:

none

Such characters are not printed at all. The conversion process stops at the first character that cannot be rendered.

copy-pass

The characters are displayed ‘as is’. Notice, that depending on your setup, this may screw-up your terminal settings.

copy-octal

Unprintable characters are represented by their octal codes. Printable ones are printed ‘as is’.

debug

Type: Boolean
Default: Unset

This variable is not used. It exists for compatibility with other mailx implementations and for future use.

dot

Type: Boolean.
Default: False.

If True, causes mail to interpret a period alone on a line as the terminator of a message you are sending.

emptystart

Type: Boolean.
Default: False.

If the mailbox is empty, mail normally prints ‘No mail for user’ and exits immediately. If this option is set, mail will start no matter is the mailbox empty or not.

editheaders

Type: Boolean.
Default: False.

When set, mail will include message headers in the text to be the ~e and ~v escapes, thus allowing you to customize the headers.

escape

Type: String.
Default: ~

If defined, the first character of this option gives the character to denoting escapes.

flipr

Type: Boolean
Default: Unset

If set, the variable flipr swaps the meanings of reply and Reply commands (see Replying).

folder

Type: String.
Default: Unset.

The name of the directory to use for storing folders of messages. If unset, $HOME is assumed.

fromfield

Type: Boolean.
Default: True.

By default the sender address is taken from the ‘From’ header. Unsetting this variable tells mail to obtain it from the SMTP envelope, instead.

See datefield.

header

Type: Boolean.
Default: True, unless started with ‘--nosum’ (‘-N’) option.

Whether to run headers command automatically after entering interactive mode.

headline

Type: String
Default: ‘%>%a%4m %18f %16d %3l/%-5o %s

A format string to use for the header summary. The ‘%’ character introduces a format specifier. Valid format specifiers are:

Letter Meaning
%a Message attributes.
%d The date when the message was received.
%f The address of the message sender.
%l The number of lines of the message.
%m Message number.
%o The number of octets (bytes) in the message.
%s Message subject (if any).
%S Message subject (if any) in double quotes.
%> A ‘>’ for the current message, otherwise a space.
%< A ‘<’ for the current message, otherwise a space.
%% A `%' character.

Some additional symbols are allowed between ‘%’ and the specifier letter. The ‘-’ character immediately following ‘%’ indicates that this field should be left aligned. Similarly, the ‘+’ character indicates right alignment. Default alignment depends on the type of the specifier: the specifiers that produce numeric values (‘%l’, ‘%m’, and ‘%o’) are aligned to the right, whereas the ones producing string values are aligned to the left.

A number following ‘%’ or the alignment flag, indicates the field width. Consider, for example, the following specifiers:

%m

Print current message number. Take as much screen columns as necessary to output it.

%4m
%+4m

Print current message number. Occupy 4 screen columns, truncate the output if it does not fit that width. Align the output to the right.

%-4m

Same as above, but align to the left.

hold

Type: Boolean.
Default: False.

When set to True, the read or saved messages will be stored in user's mailbox (‘$HOME/mbox’). Otherwise, they will be held in system mailbox also. This option is in effect only when operating upon user's system mailbox.

ignore

Type: Boolean.
Default: False.

When set to True, mail will ignore keyboard interrupts when composing messages. Otherwise an interrupt will be taken as a signal to abort composing.

ignoreeof

Type: Boolean.
Default: False.

Controls whether typing EOF character terminates the letter being composed.

indentprefix

Type: String.
Default: "\t" (a tab character).

String used by the ~m tilde escape for indenting quoted messages.

inplacealiases

Type: Boolean
Default: False

If set, mail will expand aliases in the address header field before entering send mode (see section Composing Mail). By default, the address header fields are left intact while composing, the alias expansion takes place immediately before sending message.

keep

Type: Boolean, Read-Only
Default: True

Truncate the user's system mailbox when it is empty, instead of removing it. This is the default and cannot be changed. This variable exists only for compatibility with other mailx implementations.

keepsave

Type: Boolean.
Default: False.

Controls whether saved messages should be kept in system mailbox too. This variable is in effect only when operating upon a user's system mailbox.

mailx

Type: Boolean.
Default: False.

When set, enables mailx compatibility mode. This mode has the following effects:

metamail

Type: Boolean or String.
Default: True.

This variable controls operation of decode command. If it is unset, decode will not attempt any interpretation of the content of message parts. Otherwise, if metamail is set to true, decode will use internal metamail support to interpret message parts. Finally, if metamail is assigned a string, this string is treated as command line of the external metamail command which will be used to display parts of a multipart message. For example:

 
# Disable MIME interpretation:
set nometamail
# Enable built-in MIME support:
set metamail
# Use external program to display MIME parts:
set metamail="metamail -m mail -p"
mimenoask

Type: String
Default: Empty

By default mail asks for confirmation before running interpreter to view a part of the multi-part message. If this variable is set, its value is treated as a comma-separated list of MIME types for which no confirmation is needed. Elements of this list may include shell-style globbing patterns, e.g. setting

 
set mimenoask=text/*,image/jpeg

will disable prompting before displaying any textual files, no matter what their subtype is, and before displaying files with type ‘image/jpeg’.

metoo

Type: Boolean.
Default: False.

Usually, when an alias is expanded that contains the sender, the sender is removed from the expansion. Setting this option causes the sender to be included in the group.

mode

Type: String, Read-Only
Default: The name of current operation mode.

This variable keeps the name of the current operation mode. Its possible values are:

headers

The program is started with the ‘--headers’ (‘-H’) command line option (see section Invoking mail).

exist

The program is started with the ‘--exist’ (‘-e’) command line option (see section Invoking mail).

print

The program is started with the ‘--print’ (‘-p’) command line option (see section Invoking mail).

read

The progran operates in read mode. This is the default.

send

The program operates in send mode. This means it was given one or more recipient addresses in the command line.

nullbody

Type: Boolean
Default: True

Controls whether mail accepts messages with an empty body. The default value, true, means such messages are sent, and a warning (traditionally saying ‘Null message body; hope that's ok’) is displayed. The text of the warning can be set using nullbodymsg variable (see below).

If nullbody is unset, mail will silently ignore such messages. This can be useful in ‘crontab’ files, to avoid sending mails when nothing important happens. For example, the ‘crontab’ entry below will send mail only if the utility some-prog outputs something on its standard output or error:

 
*/5 * * * * some-prog 2>&1 | \
   /bin/mail -E'set nonullbody' -s 'Periodic synchronization'
showenvelope

Type: Boolean
Default: Unset

If this variable is set, the print command will include the STMP envelope in its output.

nullbodymsg

Type: String
Default: Null message body; hope that's ok

Keeps the text of the warning, displayed by mail before sending an empty message. When available, the translation of this text, in accordance with the current locale, is displayed.

Unsetting this variable disables the warning.

onehop

Type: Boolean
Default: Unset

This variable is not used. It exists for compatibility with other mailx implementations and for future use.

outfolder

Type: String.
Default: Unset.

Contains the directory in which files created by save, write, etc. commands will be stored. When unset, current directory is assumed.

page

Type: Boolean.
Default: False.

If set to True, the pipe command will emit a linefeed character after printing each message.

prompt

Type: String.
Default: "? "

Contains the command prompt sequence.

quiet

Type: Boolean
Default: Unset

This variable is not used. It exists for compatibility with other mailx implementations and for future use.

quit

Type: Boolean.
Default: False, unless started with ‘--quit’ (‘-q’) option.

When set, causes keyboard interrupts to terminate the program.

rc

Type: Boolean.
Default: True, unless started with ‘--norc’ (‘-N’) option.

When this variable is set, mail will read the system-wide configuration file upon startup. See Personal and System-wide Configuration Files.

readonly

Type: Boolean
Default: False

When set, mailboxes are opened in readonly mode. In this mode, any mail commands that alter the contents of the mailbox are disabled. These commands include, but are not limited to: delete, save and mbox.

record

Type: String.
Default: Unset.

When set, any outgoing message will be saved to the named file.

recursivealiases

Type: Boolean
Default: True

When set, mail will expand aliases recursively.

regex

Type: Boolean.
Default: True.

Setting this to True enables use of regular expressions in ‘/.../’ message specifications.

replyprefix

Type: String
Default: ‘Re:

Sets the prefix that will be used when constructing the subject line of a reply message.

replyregex

Type: String
Default: ‘^re: *

Sets the regular expression used to recognize subjects of reply messages. If the Subject header of the message matches this expression, the value of replyprefix will not be prepended to it before replying. The expression should be a POSIX extended regular expression. The comparison is case-insensitive.

For example, to recognize usual English, Polish, Norwegian and German reply subject styles, use:

 
set replyregex="^(re|odp|aw|ang)(\\[[0-9]+\\])?:[[:blank:]]"

(Notice the quoting of backslash characters).

save

Type: Boolean.
Default: True.

When set, the aborted messages will be stored in the user's ‘dead.file’. See also appenddeadletter.

screen

Type: Numeric.
Default: Detected at startup by querying the terminal device. If this fails, the value of environment variable LINES is used.

This variable contains the number of lines on terminal screen.

sendmail

Type: String.
Default: sendmail:/usr/lib/sendmail

Contains URL of the mail transport agent.

sendwait

Type: Boolean
Default: Unset

This variable is not used. It exists for compatibility with other mailx implementations and for future use.

showto

Type: Boolean
Default: False

If the message was sent by the user, print its recipient address in the header summary.

Sign

Type: String.
Default: Unset.

Contains the filename holding users signature. The contents of this file is appended to the end of a message being composed by ~A escape.

sign

Type: String.
Default: Unset.

Contains the user's signature. The contents of this variable is appended to the end of a message being composed by ~a escape. Use Sign variable, if your signature occupies more than one line.

showto

Type: Boolean
Default: unset

If this variable is set, mail will show To: addresses instead of From: for all messages that come from the user that invoked the program.

subject

Type: String.
Default: Unset.

Contains default subject line. This will be used when asksub is off.

toplines

Type: Numeric.
Default: 5

Number of lines to be displayed by top and Top commands.

variable-strict
varstrict

Type: Boolean.
Default: False.

Setting this variable enables strict control over variable settings. In this mode, mail refuses to set read-only variables. Also, if the user is trying to set an unknown variable, mail prints a warning.

See Setting and Unsetting the Variables.

variable-pretty-print
varpp

Type: Boolean.
Default: False.

If this variable is set, the listing ouput by set contains short descriptions before each variable. See Setting and Unsetting the Variables.

verbose

Type: Boolean.
Default: False.

When set, the actual delivery of messages is displayed on the user's terminal.

xmailer

Type: Boolean.
Default: Set.

Controls whether the header ‘X-Mailer’ should be added to outgoing messages. The default value of this header is

 
X-Mailer: mail (GNU Mailutils 2.2)

2.4.7 Personal and System-wide Configuration Files

Upon startup, mail reads the contents of the two command files: the system-wide configuration file, and the user's configuration file. Each line read from these files is processed like a usual mail command.

When run with ‘--norc’ (‘-N’) option, mail does not read the contents of system-wide configuration file. The user's file, if it exists, is always processed.

The user's configuration file is located in the user's home directory and is named ‘.mailrc’. The location and name of the system-wide configuration file is determined when configuring the package via ‘--with-mail-rc’ option. It defaults to ‘sysconfdir/mail.rc’.