GNU Mailutils Manual (split by section):   Section:   Chapter:FastBack: Programs   Up: Programs   FastForward: Libraries   Contents: Table of ContentsIndex: Function Index

3.5 mail — Send and Receive Mail

Editor’s note:

The information in this node may be obsolete or otherwise inaccurate. This message will disappear, once this node revised.

Mail is an enhanced version of POSIX mailx program. The program operates in two modes: read and send.

Mail enters send mode when at least one email address was specified in its 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 the user to read and manipulate the contents of the user system mailbox. Use the --file (-f) option to specify another mailbox name. For more detail, see Reading Mail.

In addition to the Mailutils configuration file, mail reads the traditional ‘mailrc’-style configuration files. See Mail Configuration Files, for a detailed description of their format.

3.5.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.

Mail understands the following command line options:

-A file
--attach=file

Attach file to the composed message. The encoding, content type, and content description are controlled by the --encoding, --content-type, and --content-name options, correspondingly.

The option --attach=- instructs mail to read the file to be attached from the standard input. Interactive shell is disabled in this case.

--attach-fd=fd

Read attachment body from the file descriptor fd. The descriptor must be open for reading. This option is useful when calling mail from another program.

See the options --encoding, --content-type, --content-name, and --content-filename.

-a header:value
--append=header:value

Append the given header to the composed message.

--content-type=type

This options sets the content type to be used by all subsequent --attach options.

--content-filename=name

Set the ‘filename’ parameter in the ‘Content-Disposition’ header for the next --attach-fd option.

--content-name=text

Set the ‘name’ parameter (description) in the ‘Content-Type’ header for the next --attach or --attach-fd option.

-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 Mail Configuration Files), but before opening the mailbox.

-e
--exist

Return true if the mailbox contains some messages. Return false otherwise.

This is useful for writing shell scripts.

--encoding=enc

Sets content transfer encoding for use by the subsequent --attach options.

-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.

-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 Reading Mail, for more details about using this option.

-H
--headers

Print header summary to stdout and exit.

-i
--ignore

Ignore interrupts when composing the message.

-M
--mime
--no-mime

The --mime option instructs mail to compose MIME messages. It is equivalent for -E 'set mime', except that it is processed after all other options. The --no-mime disables the MIME compose mode, and is a shortcut for -E 'set nomime',

-N
--nosum

Do not display initial header summary.

-n
--norc

Do not read the system-wide mailrc file. See Mail Configuration Files.

-p
--print
--read

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

print *
quit

except that mail --print does not change status of the messages.

-q
--quit

Cause interrupts to terminate program.

-r address
--return-address=address

Sets the return email address for outgoing mail. See return-address.

--skip-empty-attachments
--no-skip-empty-attachments

Don’t create attachments that would have zero-size body. This option affects all attachments created by --attach and --attach-fd options appearing after it in the command line, as well as the body of the original message.

To cancel its effect, use the --no-skip-empty-attachments option.

-s subj
--subject=subj

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

-t
--to

Read recipients from the message header. Ignore addresses listed in the command line.

-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).

The program also understands the common mailutils options (see Common Options.

3.5.2 Reading Mail

The mail utility operates on three kinds of mailboxes. The user system mailbox is the mailbox where the incoming mail for the user is stored. Its location is system-dependent and is determined using the common mailutils rules (see mailbox statement). The personal mailbox (or mbox, for short) is the default location for saving messages that have been read. By default it is $HOME/mbox or whatever file specified by the MBOX environment variable. Any other mailboxes are called secondary mailboxes.

When called without arguments, mail opens the system mailbox for the invoking user. The --file (-f) used without arguments instructs mail to operate on the personal mailbox instead. When this option and a single command line argument are used together, mail treats the argument as the pathname of the secondary mailbox to operate upon.

Notice that this argument is not an argument to the --file (-f) option itself, but rather the first non-optional argument on the command line. This means that any number of additional options are allowed between the --file option and the mailbox file name. For example, 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

The --user (-u) option allows the system administrator to assume another user identity for operating on this user’s mailboxes. Obviously, it is available only to system administrators. For example:

mail --user=tom

reads mail from the system mailbox of the user ‘tom’, and

mail --user=tom --file

reads mail from the personal mailbox of this user.

Unless you have started mail with --norc command line option, it will read the contents of the system-wide configuration file. Then it will read the contents of user configuration file, if it exists. For detailed description of these files, see Mail Configuration Files. After this initial setup, mail displays the first page of header lines (unless the -N option has been given), followed by a prompt, indicating that it is waiting for regular commands. Upon receiving a command, mail parses and executes it, displays the result on the screen, prints the prompt and waits for the next command. This process is continued until mail receives any of the commands ‘quit’, ‘exit’ or the end-of-file character (ASCII 4, or C-D).

Each message in the mailbox has a state that affects how it is retained or deleted upon closing the mailbox when terminating the program (see the quit command) or when switching to another mailbox (see the file command). The state is reflected in the header listing and can be changed during the session. The states are:

new

The message is present in the system mailbox and has not been read by the user or moved to any other state. When mail terminates, messages in this state are retained in the system mailbox. If the mailbox is closed, such messages are moved to the ‘unread’ state.

unread

The message has been present in the system mailbox for more than one invocation of mail and has not been read by the user or moved to any other state. When mail terminates, messages in this state are retained in the system mailbox.

read

The message has been read by the user, i.e. processed by one of the following commands: copy, mbox, next, pipe, prev, print, Print, struct, top, type, Type, undelete, or any of the following escapes (in message compose mode): ~f, ~m, ~F, ~M.

When mail terminates, messages in this state are handled depending on the mailbox they are in.

If mail was operating on the user system mailbox, all messages in state ‘read’ are preserved. The location where they are preserved is determined by the hold variable (see Mail Variables). If it is not set (the default), the messages are moved to the user’s mbox. If hold is set, the messages are held in the system mailbox instead.

The ‘read’ messages in any other mailbox will be retained in their current location.

deleted

The message has been processed by one of the following commands: ‘delete’, ‘dp’, ‘dt’. Messages in this state are ignored by any command, excepting ‘undelete’, which changes their state back to ‘read’. When closing the mailbox, deleted messages are permanently removed from the mailbox.

preserved

The message has been processed by the preserve (hold) command. When closing the mailbox, such messages are retained in the mailbox.

saved

The message has been processed by one of the following commands: save, write. When mail terminates, messages in this state are handled depending on the mailbox they are in.

If mail was operating on the user system mailbox, the default behavior for ‘saved’ messages is to remove them from the system mailbox. If, however, the keepsave variable is set, they are preserved using the same rules as for ‘read’ messages (see above).

Saved messages in non-system mailboxes are retained in their current location.

Unless the mailbox is empty, exactly one of its messages will be marked as current message. Upon startup, current message is set to the first new message, if there is any, or the first unread message if there is any, or to the first message in the mailbox. In the header listing, current message is marked with the ‘>’ sign at the beginning of the line. Current message is changed by any of the following commands: ‘dp’, ‘prev’, ‘next’.

3.5.2.1 Syntax of mail internal commands

Commands have the following syntax:

command [msglist] [argument ...]

A command is terminated by a newline character. Empty command (i.e. a newline character alone) is equivalent to ‘next’ (see next).

In the syntax above, command is the command verb. Each command has long and short (abbreviated) form. Each of them can be used to invoke the command.

Many mail commands take a list of messages (msglist) to operate upon, which defaults to current message.

The list of messages 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

n

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

n-m

All messages with ordinal numbers between n and m, inclusive.

:t

All messages of type t, where t can be any of:

d

Deleted messages.

n

New messages.

o

Old messages (any message not in state ‘read’ or ‘new’).

r

Messages in state ‘read’.

u

Messages in state ‘unread’.

t

Selects all tagged messages.

T

Selects all untagged messages.

s

Selects all messages in state ‘saved’.

[header:]/string[/]

Header match.

Selects all messages that contain header field header matching given string. If the variable regex is set, the string is assumed to be a POSIX regexp. (All comparison is case-insensitive in either case).

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

:/string[/]

Message body match.

Selects all messages with body matching the string. The matching rules are the same as described above.

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:

3

Third message.

1-4 10

Messages from 1 through 4 and message 10.

4-*

All messages starting from message 4.

/watch

All messages with the word ‘watch’ in the subject.

/watch :/watch

All messages with the word ‘watch’ in the subject or body.

/watch :/watch $

Same as above plus the last message in the mailbox.

10[2]

Part 2 of the multipart message 10.

3.5.2.2 Quitting the Program

Following commands quit the program:

Mail command: quit

Terminates the session. The messages, marked with delete are removed. The messages in state ‘read’ and ‘saved’ are processed depending on the mailbox they are in.

If mail was operating on the user system mailbox, all messages in state ‘read’ are preserved. The location where they are preserved is determined by the hold variable. If it is not set (the default), the messages are moved to the user’s mbox. If hold is set, the messages are held in the system mailbox instead.

The default behavior for ‘saved’ messages is to remove them from the system mailbox. If, however, the keepsave variable is set, they are preserved using the same rules as for ‘read’ messages.

For non-system mailboxes, both ‘read’ and ‘saved’ messages are retained in their current location.

The same rules are followed when the mailbox is switched using the file command.

The program exits to the shell, unless saving the mailbox fails, in which case user can escape with the exit command.

Mail command: exit
Mail command: ex
Mail command: xit

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

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

3.5.2.3 Obtaining Online Help

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

Mail command: help [command]
Mail command: hel [command]
Mail command: ? [command]

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

Mail command: list
Mail command: *

Print a list of available commands.

Mail command: version
Mail command: ve

Display program version.

Mail command: warranty
Mail command: wa

Display program warranty statement.

3.5.2.4 Moving Within a Mailbox

Mail command: ^

Move to the first undeleted message.

Mail command: $

Move to the last undeleted message.

Mail command: next
Mail command: n

Move to the next message.

Mail command: previous
Mail command: prev

Move to the previous message.

3.5.2.5 Changing Mailbox/Directory

Mail command: cd [dir]
Mail command: chdir [dir]
Mail command: ch [dir]

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

Mail command: file [mailbox]
Mail command: fi [mailbox]
Mail command: folder [mailbox]
Mail command: fold [mailbox]

When used without argument, prints the information about the current mailbox: the mailbox file name (or URL), total number of messages and the number of unread messages, e.g.:

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

Otherwise, closes the current mailbox and opens the mailbox named by the mailbox argument. When closing the current mailbox, its messages are processed according to their state (see mail message states).

The mailbox argument can be the name of the existing file, a mailbox URL (see Mailbox), or any of the following shortcuts:

%

The system mailbox for the invoking user.

%user

The system mailbox for user.

#

The previous file.

&

The user’s personal mailbox.

@

Secondary mailbox, given using the -f command line option.

+file

The named file in the folder directory. See folder variable.

3.5.2.6 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.

Mail command: discard [header-field-list]
Mail command: di [header-field-list]
Mail command: ignore [header-field-list]
Mail command: ig [header-field-list]

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

Mail command: retain [header-field-list]
Mail command: ret [header-field-list]

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

3.5.2.7 Displaying Information

Mail command: =

Displays the current message number.

Mail command: headers [msglist]
Mail command: h [msglist]

Lists the current pageful of headers.

Mail command: from [msglist]
Mail command: f [msglist]

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

Mail command: 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.

Mail command: size [msglist]
Mail command: si [msglist]

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

Mail command: folders

Displays the value of folder variable.

Mail command: summary
Mail command: su

Displays current mailbox summary. E.g.:

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

3.5.2.8 Displaying Messages

Mail command: print [msglist]
Mail command: p [msglist]
Mail command: type [msglist]
Mail command: 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.

Mail command: Print [msglist]
Mail command: P [msglist]
Mail command: Type [msglist]
Mail command: T [msglist]

Like print but also prints out ignored header fields.

Mail command: decode [msglist]
Mail command: 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
...
Mail command: top [msglist]
Mail command: 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.

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

Pipe the contents of specified messages through shell-command. Without arguments, pipe the current message through the command given by the ‘cmd’ variable (which must be set).

Mail command: 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

3.5.2.9 Marking Messages

Mail command: tag [msglist]
Mail command: ta [msglist]

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

Mail command: untag [msglist]
Mail command: unt [msglist]

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

? untag :t
Mail command: hold [msglist]
Mail command: ho [msglist]
Mail command: preserve [msglist]
Mail command: pre [msglist]

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

Mail command: unread [msglist]

Marks each message from the msglist as not having been read.

3.5.2.10 Disposing of Messages

Mail command: delete [msglist]
Mail command: 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.

Mail command: undelete [msglist]
Mail command: u [msglist]

Clear delete mark from the specified messages.

Mail command: dp [msglist]
Mail command: 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.

3.5.2.11 Saving Messages

Mail command: save [[msglist] mailbox]
Mail command: s [[msglist] mailbox]

Takes a message list and a file or mailbox name and appends each message in turn to that file or mailbox. The syntax for mailbox is the same as for the file command (see Mailbox shortcuts). The name of the mailbox and number of lines and characters appended to it is echoed on the terminal. When writing to file, the numbers represent exact number of lines and characters appended to the file. When file specifies a mailbox, these numbers may differ by the amount of lines/characters needed to represent message envelope for that specific mailbox type.

Each saved message is marked for deletion as if with delete command, unless the variable keepsave is set.

Mail command: Save [msglist]
Mail command: S [msglist]

Like save, but the file to append messages to is named after the sender of the first message in msglist. The file name is selected as described in saving mail by name. 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.

Mail command: write [[msglist] file]
Mail command: w [[msglist] file]

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

Mail command: Write [msglist]
Mail command: W [msglist]

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

Mail command: mbox [msglist]
Mail command: mb [msglist]

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

Mail command: touch [msglist]
Mail command: tou [msglist]

Touch the specified messages. If any message in msglist is not specifically deleted nor saved in a file, upon normal termination it will be acted upon as if it had been read (see mail message states).

Mail command: copy [[msglist] file]
Mail command: c [[msglist] file]

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

Mail command: Copy [msglist]
Mail command: C [msglist]

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

3.5.2.12 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.

Mail command: edit [msglist]
Mail command: e [msglist]

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

Mail command: visual [msglist]
Mail command: v [msglist]

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

3.5.2.13 Aliasing

Mail command: alias [alias [address...]]
Mail command: a [alias [address...]]
Mail command: group [alias [address...]]
Mail command: 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.

Mail command: unalias [alias...]
Mail command: 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.

Mail command: alternates name...
Mail command: 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.

3.5.2.14 Replying

Mail command: mail [address...]
Mail command: m [address...]

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

If the record variable is set, the composed message will be saved in the folder named by it.

Mail command: Mail [address...]
Mail command: M [address...]

Same as mail, but the name of the file to save the composed message is derived from its first recipient as outlined below.

If the outfolder variable is set, and has a string value s, the filename is s/recipient. If it is a boolean, then the folder variable is consulted. If it is set, then the filename is folder/recipient. Otherwise, the message will not be saved.

The value recipient is derived from the email of the first recipient of the message. By default it is a local part of that email. If the outfilename variable has the value ‘domain’, the domain part of the email is used. If this variable is set to ‘email’, then entire email address is used.

See saving mail by name, for a detailed discussion.

Mail command: reply [message]
Mail command: respond [message]
Mail command: r [message]

Mail a reply message to all recipients included in the header of the message. The subject header is formed by concatenating the value of the replyprefix variable and the subject from the message. If record is set to a filename, the response is saved at the end of that file.

Mail command: Reply [msglist]
Mail command: Respond [msglist]
Mail command: R [msglist]

Mail a reply message to the sender of each message in the msglist. The subject header is formed by concatenating the value of the replyprefix variable and the subject header of from the first message in msglist. If record is set to a filename, the response is saved at the end of that file.

Notice, that setting mail variable flipr (see Mail Variables) swaps the meanings of the two above commands

Mail command: followup [message]
Mail command: fo [message]

Respond to message, recording the response in a file whose name is derived from the author of the message. See saving mail by name, for a discussion of how the file name is selected.

Mail command: Followup [msglist]
Mail command: F [msglist]

Same as Reply, but the response is saved in a file whose name is derived from the author of the first message. See saving mail by name, for a detailed discussion of how the file name is selected.

By default, mail will preserve personal email parts when forming lists of recipient addresses. If this is not desired, unset the fullnames variable (see fullnames).

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

3.5.2.15 Controlling Sender Fields

When mail needs to know the sender of a message, it looks it up in one or more headers of that message. Such headers constitute a sender list. The first header from the list that is present in the message and has a non-empty value is used. If none is found or if the sender list is empty, the value of the message envelope is used.

The commands sender and nosender manipulate the sender 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

3.5.2.16 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.

3.5.2.17 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 !.

3.5.3 Saving and Recording

Several commands discussed in the previous section save messages in a disk file. The name of that file is either obtained from the record variable (recording mail) or is derived from the first recipient of the message (saving by name).

The following commands record mails:

The following commands save mail by name:

Saving mail by name is controlled by three mail variables: outfolder, folder, and outfilename. The first, outfolder, is a boolean variable which, when set, enables saving mail by name. The folder variable defines a directory where mail files are stored. Name of file in that directory where the message will be saved is derived from the message recipient2. This process is controlled by the outfilename variable: if its value is ‘local’, the file is named by the local part of the email (this is the default). If it is ‘domain’, the domain part is used instead. Finally, if it’s value is ‘email’, the entire email is used.

As a GNU extension, outfolder can be a string variable. In that case its value names the directory to use instead of folder.

The mailx variable, if set, disables GNU extensions. In this case, outfolder is used as a boolean value, and file names are derived from the local part of the email, ignoring the outfilename value.

3.5.4 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 and the standard input is connected to a terminal. 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 Mail Variables).

3.5.4.1 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.

3.5.4.2 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.

3.5.4.3 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.

3.5.4.4 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.

3.5.4.5 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.

3.5.4.6 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

3.5.4.7 Attaching a File to the Message

The ‘~+’ escape attaches a file to the message. It takes one to three arguments. The first argument supplies the name of the file to attach:

~+ myfile.txt

The file will be attached with default content-type ‘application/octet-stream’, and encoding ‘base64’ (these can be altered by the --content-type and --encoding command line options, correspondingly).

Optional second argument defines the content type to be used instead of the default one. Optional third argument defines the encoding, e.g.:

~+ myfile.html text/html base64

To list the files attached so far, use the ‘~l’ escape:

~l
multipart/mixed
   1 myfile.html text/html base64

The first line of the output shows the content type of the message. Each subsequent line contains the ordinal number of the attachment, the name of the file, content-type and transfer encoding used.

The ‘~/’ escape toggles the content type bewteen ‘multipart/mixed’, and ‘multipart/alternative’. The new value of the content type is displayed on the screen.

The ‘~^’ escape removes attachments. Its argument is the number of the attachment to remove, e.g.:

~^ 1

3.5.4.8 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.

3.5.4.9 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.

3.5.4.10 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.

3.5.4.11 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.

3.5.4.12 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.

3.5.4.13 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.

3.5.5 Composing Multipart Messages

Multipart messages (or MIME, for short) can be used to send text in character sets other than ASCII, attach non-text files, send multiple parts in alternative formats, etc.

Technically speaking, the boolean variable mime controls this feature. If it is set (see Setting and Unsetting the Variables), MIME will create MIME messages by default. The variable can be set in the global or user configuration file (see Mail Configuration Files), using the following command:

set mime

It can also be set from the command line, using the --mime option.

GNU mail automatically turns on the MIME mode, when it is requested to send a non-plaintext message, or a message in character set other than ASCII, when the encoding is specified, or when attachments are given.

To send a message in another character set, specify it with the --content-type option:

mail --content-type 'text/plain; charset=utf-8'

The --encoding specifies the encoding to use:

mail --content-type 'text/plain; charset=utf-8' --encoding=base64

Its argument is any encoding supported by GNU mailutils. The two most often used encodings are ‘base64’ and ‘quoted-printable’.

To specify the charset from mail interactive section, enable the “edit headers” mode (set editheaders) and add the needed Content-Type header manually.

GNU mail also gives you a possibility to attach files to the message being sent.

The simplest way to attach a file from command line is by using the --attach (-A) option. Its argument specifies the file to attach. For example, the following will attach the content of the file archive.tar:

$ mail --attach=archive.tar

By default, the content type will be set to ‘application/octet-stream’, and the attachment will be encoded using the ‘base64’ encoding. To change the content type, use the --content-type option. For example, to send an HTML attachment:

$ mail --content-type=text/html --attach=in.html

The --content-type option affects all --attach options that follow it, and the message body (if any). To change the content type, simply add another --content-type option. For example, to send both the HTML file and the archive:

$ mail --content-type=text/html --attach=in.html \
       --content-type=application/x-tar --attach=archive.tar

To change the content type of the message body when sending a message with attachments, use the trailing --content-type option, i.e. the option not followed by another --attach option:

$ mail --content-type=text/html --attach=in.html \
       --content-type=application/x-tar --attach=archive.tar \
       --content-type=text/plain

This example adds two attachments with different content types and switched back to the ‘text/plain’ content type for the message body.

The encoding to use is set up by the --encoding option. As well as --content-type, this option affects all attachments supplied after it in the command line as well as the message body read from the standard input, until changed by the eventual next instance of the same option. Extending the above example:

$ mail --content-type=text/html --encoding=quoted-printable \
       --attach=in.html \
       --content-type=application/x-tar --encoding=base64 \
       --attach=archive.tar

A trailing --encoding option sets the encoding of the message body.

Each attachment can also be assigned a description and a file name. Normally, these are the same as the file name supplied with the --attach option. However, you can change either or both of them using the --content-name and --content-filename, correspondingly. Both of these options affect only the next --attach (or --attach-fd, see below) option.

By default, the message will be assigned the content type ‘multipart/mixed’. To change it to ‘multipart/alternative’, use the --alternative command line option. Using this option also sets the ‘Content-Disposition’ header of each attached message to ‘inline’.

All the examples above will enter the usual interactive shell, allowing you to compose the body of the message. If that’s not needed, the non-interactive use can be forced by redirecting /dev/null to the standard input, e.g.:

$ mail --attach=archive.tar < /dev/null

This will normally produce a message saying:

mail: Null message body; hope that's ok

To suppress this message, unset the ‘nullbodymsg’ variable, as shown in the example below:

$ mail -E 'set nonullbodymsg' --attach=archive.tar < /dev/null

The option --attach=- forces mail to read the file to be attached from the standard input stream. This option disables the interactive mode and sets ‘nonullbodymsg’ implicitly, so that the above example can be rewritten as:

$ mail --attach=- < archive.tar

Special option is provided to facilitate the use of mail in scripts. The --attach-fd=N instructs the program to read the data to be attached from the file descriptor N. The above example is equivalent to:

$ mail --attach-fd=0 < archive.tar

Attachments created with this option have neither filename nor description set, so normally the use of --content-name and/or --content-filename is advised.

The option --skip-empty-attachments instructs mail to skip creating attachments that would have zero-size body. This option affects all attachments created by --attach and --attach-fd options appearing after it in the command line. It also affects the handling of the original message body. To cancel its effect, use the --no-skip-empty-attachments option.

Here are some examples illustrating how it works.

First, consider the following command line

$ mail --attach=archive.tar </dev/null

Assume that archive.tar is not empty.

This will create a MIME message of two parts: the first part having ‘text/html’ type and empty body, and the second part of type ‘application/octet-stream’, with the content copied from the file archive.tar.

Now, if you do:

$ mail --attach=archive.tar --skip-empty-attachments </dev/null

then the created MIME message will contain only one part: that containing archive.tar.

If the file archive.tar has zero length, the resulting archive will still contain the ‘application/octet-stream’ part of zero length. However, if you place the --skip-empty-attachments option before --attach, then the produced message will be empty.

The following Perl program serves as an example of using mail from a script to construct a MIME message on the fly. It scans all mounted file systems for executable files that have setuid or setgid bits set and reports the names of those files in separate attachments. Each attachment is named after the mountpoint it describes.

The script begins with the usual prologue stating the modules that will be used:

#!/usr/bin/perl

use strict;
use autodie;

Then global variables are declared. The ‘@rcpt’ array contains the email addresses of the recipients:

my @rcpt= 'root@example.com';

The ‘@cmd’ variable holds the mail command line. It will be augmented for each file system. The initial value is set as follows:

my @cmd = ('mail',
           '-E set nonullbodymsg',
           '--content-type=text/plain');

The find utility will be used to locate the files. The script will start as many instances as there are mountpoints. Those instances will be run in parallel and their standard output streams will be connected to file descriptors passed to mail invocation in --attach-fd options.

The descriptors will be held in ‘@fds’ array. This will prevent them from being wiped out by the garbage collector. Furthermore, care should be taken to ensure that the O_CLOEXEC flag be not set for these descriptors. This sample script takes a simplistic approach: it instructs Perl not to close first 255 descriptors when executing another programs:

my @fds;
$^F = 255;

The following code obtains the list of mount points:

open(my $in, '-|', 'mount -t nonfs,noproc,nosysfs,notmpfs');
while (<$in>) {
    chomp;
    if (/^\S+ on (?<mpoint>.+) type (?<fstype>.+) /) {

For each mountpoint, the find command line is constructed and launched. The file descriptor is pushed to the ‘@fds’ array to prevent it from being collected by the garbage collector:

	open(my $fd, '-|',
	     "find $+{mpoint} -xdev -type f"
             . " \\( -perm -u+x -o -perm -g+x -o -perm -o+x \\)"
             . " \\( -perm -u+s -o -perm -g+s \\) -print");
	push @fds, $fd;

Now, the mail command is instructed to create next attachment from that file descriptor:

        my $mpname = $+{mpoint};
        $mpname =~ tr{/}{%}; 
        push @cmd,
             "--content-name=Set[ug]id files on $+{mpoint} (type $+{fstype})",
             "--content-filename=$mpname.list",
             '--attach-fd=' . fileno($fd);
    }
}
close $in;

Finally, the emails of the recipients are added to the command line, the standard input is closed to make sure mail won’t enter the interactive mode and the constructed command is executed:

push @cmd, @rcpt;
close STDIN;
system(@cmd);

3.5.6 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.

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@example.com gray@example.org
set

3.5.7 How to Alter the Behavior of mail

Following variables control the behavior of GNU mail:

mail: boolean append

Default: True
Comment: Read-Only

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.

mail: boolean appenddeadletter

Default: False

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

mail: boolean askbcc

Default: False

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

mail: boolean askcc

Default: True

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

mail: boolean asksub

Default: True in interactive mode, False otherwise.

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

mail: boolean autoinc

Default: True

Automatically incorporate newly arrived messages.

mail: boolean autoprint

Default: False

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

mail: boolean bang

Default: False

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

See Executing Shell Commands, for details on the ! escape.

mail: boolean datefield

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.

mail: string charset

Default: ‘auto

The value of this variable is the character set used for input and output operations. If the value is ‘auto’, mail will try to deduce the name of the character set from the value of LC_ALL environment variable. If the variable contains the character set part (e.g. ‘nb_NO.utf-8’), it will be used. Otherwise, mail will look up in its built-in database the value of the character for this language/territory combination. If LC_ALL is not set, the LANG environment variable is inspected.

The value of charset controls both input and output operations. On input, it is used to set the value of the ‘charset’ parameter in the ‘Content-Type’ MIME header, if its value begins with ‘text/’ and the ‘charset’ parameter is not present.

On output, it is used to display values of the header fields encodied using RFC 2047. If the variable is unset, no decoding is performed and the fields are printed as they are. Otherwise, they are recoded to that character set.

mail: string cmd

Default: Unset

Contains default shell command for pipe.

mail: numeric columns

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.

mail: numeric crt
mail: boolean crt

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.

mail: boolean debug
mail: string debug

Default: Unset

Sets mailutils debug level. If set to string, the value must be a valid Mailutils debugging specification. See 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.

mail: string decode-fallback

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’.

mail: boolean dot

Default: False

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

mail: boolean editheaders

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.

mail: boolean emptystart

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.

mail: string escape

Default: ‘~

Current value of the command escape character.

mail: boolean flipr

Default: Unset

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

mail: string folder

Default: Unset

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

mail: boolean fromfield

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.

mail: boolean fullnames

Default: True

Preserve personal parts (comments) of recipient addresses when replying to a message.

When unset, only emails will be used.

See Replying.

mail: boolean header

Default: True, unless started with --nosum (-N) option.

Whether to run headers command automatically after entering interactive mode.

mail: string headline

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

Format string to use for the header summary. The ‘%’ character introduces a format specifier. The format specifier consists of optional alignment specifier (‘+’ or ‘-’ sign), optional output width and the specifier letter. Format specifiers are replaced on output with the corresponding piece of information from the message being described.

The ‘-’ character immediately following ‘%’ indicates that this field should be left aligned. 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 or date/time values are aligned to the left.

A number following ‘%’ or the alignment flag, indicates the field width.

Consider the ‘%m’ specifier as an example:

%m

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

%4m
%+4m

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

%-4m

Same as above, but align to the left.

Valid format specifiers are:

%a

Message attribute. One of the following letters, or a single horizontal space, if none of them applies:

Mthe message was copied to the mailbox (mbox command)
Pthe message was preserved (hold command)
*the message was saved (save or Save)
Tthe message was tagged (tag)
Rthe message was read
Nthe message is new (was not seen)
Uthe message was seen, but wasn’t read
%d

The date when the message was received. It is determined from the message header defined by the ‘datefield’ variable (see datefield). If that variable is not set, or the requested header is not present in the message, the date from the envelope is used.

The output is formatted according to the following format specification (see Date/time Format String):

%a %b %e %H:%M

I.e.: abbreviated weekday name, abbreviated month name, day of the month as a decimal number, followed by hour and minutes. All names are displayed according to the current locale.

%D{fmt}

Same as ‘%d’, but the date is formatted according to the date/time format fmt. It is essentially a C ‘strftime’ format string, described in detail in Date/time Format String.

For example:

set headline="%4m %20D{%Y-%m-%dT%H:%M:%S}"

Note, that the opening ‘{’ must follow the format letter without any intervening whitespace. If fmt contains ‘{’, ‘}’, or ‘\’, these characters must be escaped with backslash (e.g. ‘\{’).

%Df

A simplified form of the ‘%D’ specifier. It is equivalent to

%D{%f}

where f is a single ‘strftime’ specifier letter. It can be preceded by ‘E’ or ‘O’, if the Single UNIX Specification allows such usage (see conversion specs), e.g. ‘%DOU’.

Notice, that ‘%D’ not followed by a valid time format in either of the above forms is treated as unknown specifier.

%f

The email 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.

mail: boolean hold

Default: False

Determines the location where to store the messages in state ‘read’ and (if the keepsave is also set) ‘saved’. When set, these messages will be retained in the system mailbox.

When not set (the default), such messages will be stored in the user’s personal mailbox.

See read messages, and See saved messages, for a detailed information on how such messages are processed when the mailbox is being closed.

See keepsave, for the discussion of the keepsave variable.

mail: boolean ignore

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.

mail: boolean ignoreeof

Default: False

Controls whether typing EOF character terminates the letter being composed.

mail: string indentprefix

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

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

mail: boolean inplacealiases

Default: False

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

mail: boolean keep

Comment: 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.

mail: boolean keepsave

Default: False

Controls whether saved messages should be retained. The location where they will be retained is controlled by the hold variable (see the hold variable).

This variable is in effect only when operating upon the user’s system mailbox.

See saved messages, for a detailed information on how the saved messages are processed when the mailbox is being closed.

mail: boolean mailx

Default: False

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

mail: boolean metamail
mail: string metamail

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"
mail: string mime

Default: False

If set, this variable instructs mail to compose MIME messages.

It can be set from the command line using --mime option.

mail: string mimenoask

Default: Unset

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’.

mail: boolean metoo

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.

mail: string mode

Comment: 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 Invoking Mail).

exist

The program is started with the --exist (-e) command line option (see Invoking Mail).

print

The program is started with the --print (-p) command line option (see Invoking Mail).

read

The program 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.

mail: boolean nullbody

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'
mail: string nullbodymsg

Default: ‘Null message body; hope that's ok

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.

mail: boolean onehop

Default: Unset

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

mail: string outfilename

Comment: Three-state: ‘local’, ‘email’, ‘domain’.
Default: ‘local

Defines the algorithm to convert the recipient email to the name of the file used to record outgoing messages to that recipient. This affects the following commands: Copy, Save, Mail, followup, and Followup. The following values are allowed:

local

Local part of the email address is taken as the file name. This is the default.

email

Entire email is takes as the file name.

domain

Domain part of the email is used as the file name.

mail: boolean outfolder
mail: string outfolder

Default: Unset

When set as boolean, causes the files used to record outgoing messages to be located in the directory specified by the folder variable (unless the pathname is absolute).

If set to a string value, names the directory where to store these files.

This variable affects the following commands: Copy, Save, Mail, followup, and Followup.

In mailx compatibility mode, only boolean value is allowed. see mailx mail variable.

mail: boolean page

Default: Unset

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

mail: string PID

Comment: Read-Only
Default: PID of the process.

PID of the current mail process.

mail: string prompt

Default: "? "

Contains the command prompt sequence.

mail: boolean quiet

Default: Unset

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

mail: boolean quit

Default: False, unless started with --quit (-q) option.

When set, causes keyboard interrupts to terminate the program.

mail: boolean rc

Default: True, unless started with --norc (-N) option.

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

mail: boolean readonly

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.

mail: string record

Default: Unset

When set, outgoing messages produced by the following commmands will be saved to the named file: mail, reply, Reply.

See also outfolder and outfilename.

mail: boolean recursivealiases

Default: True

When set, mail will expand aliases recursively.

mail: boolean regex

Default: True.

If set, enables the use of regular expressions in ‘/.../’ message specifications.

mail: string replyprefix

Default: ‘Re:

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

mail: string replyregex

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 value 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).

mail: string return-address

Default: unset

Sets the return email address to use when sending messages. If unset, return address is composed from the current user name and the host name.

mail: boolean save

Default: True.

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

mail: numeric screen

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. See also crt.

mail: string sendmail

Default: ‘sendmail:/usr/lib/sendmail

Contains URL of the mail transport agent. If the value begins with a scheme specifier, it must be one of the mailer URL schemes supported by mailutils (see mailer URL). Otherwise, if not in mailx compatibility mode, the value starting with directory separator (‘/’) is treated as the external command that will be started as is and the composed message will be piped to its standard input.

In mailx compatibility mode (see mailx mail variable), the ‘sendmail:’ prefix is assumed.

mail: boolean sendwait

Default: Unset

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

mail: string Sign

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.

mail: string sign

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.

mail: boolean showenvelope

Default: Unset

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

mail: boolean showto

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.

mail: string subject

Default: Unset

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

mail: numeric toplines

Default: 5

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

mail: boolean variable-pretty-print
mail: boolean varpp

Default: False

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

mail: boolean variable-strict
mail: boolean varstrict

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.

mail: boolean verbose

Default: False

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

mail: boolean useragent

Default: True

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

User-Agent: mail (GNU Mailutils 3.14)
mail: boolean xmailer

This header is retained for compatibility with previous releases of GNU Mailutils. Since version 3.13 it is an alias for useragent.

3.5.8 Personal and System-wide Configuration Files

After processing the usual Mailutils configuration files (see configuration), mail reads the contents of the two command files: the system-wide command file, and the user’s command 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.

Footnotes

(2)

In case of Copy and Save, message sender is used instead

GNU Mailutils Manual (split by section):   Section:   Chapter:FastBack: Programs   Up: mail   FastForward: Libraries   Contents: Table of ContentsIndex: Function Index