You have a fresh install
and the only way to read
your welcome message from Theo
However, upon launching
Unix-like systems have offered
as a way to read the system mailbox
and send mail.
While not as flashy or featureful as more modern
(or even graphical MUAs like
it provides a surprising bit of functionality
hidden under the hood.
Over the years,
a variety of
programs have called themselves some form of "mail",
with subtle differences in each of them.
For purposes of this post,
I'll try to stick mostly to
as defined by POSIX
- no IMAP/POP/SMTP support
no Maildir or MH support,
- no built-in spam filtering
- no threading
no native support for
types other than
Specifically, all examples here
should work in
as provided by
This post assumes some basic system configuration and will discuss the three essential modes of operation:configuration settings as well as some tips & tricks.
System configuration expectations
To exchange mail with external systems,
you'll have to configure your
as well as possibly modify your
to point your
record at your server,
and you might want some sort of spam-filtering solution in place.
However, since MTA choice & configuration
fall outside the scope of this post,
use whatever you prefer
as long as your
delivers to the user's system
and your MTA has compatibility with
(usually done through a binary or link at
resides on an
share with unreliable locking,
you may encounter issues/conflicts
if more than one process attempts to modify the mailbox.
Essential modes of operation
The most simple of the modes,
this expects the email message body on
an optional subject passed with the
fields with the
followed by the list of recipient(s).
Send mode works well in scripts
to email output of commands,
Mail reading mode
If you currently have mail in your system mailbox,
POSIX shells should inform you (roughly) every
(default=600, or 10 minutes)
if the last-modified time
of the system mailbox
(as specified by
To quit back to your shell without modifying the mailbox, use the x/exit command.
If you use the
command or type
to send an
it will change the message status of unread messages from
if you have read any of the messages in your system mailbox,
they will get moved to
upon quitting with
M send to
mbox, and * saved)
- message index
- size (in lines and bytes)
If you have more than one screenful of messages,
you can use the
command to list the next screenful,
to list the previous screenful,
to re-display the current screenful.
When you first start
To list message summaries matching particular criteria, you can use the f/from command with a message-list filter. Message-list filters can consist of a single message number,
multiple message numbers,
or a range of numbers:
You can use a $ to indicate the last message in the mailbox:
These can combine to list particular messages by number & range:
If you want to refer to all messages in the mailbox, you can use *
though this may scroll past if you have more than one screenful of messages.
Additionally, you can list messages by category of message
- deleted messages
- new messages
- old messages
- read messages
- unread messages
Finally, you can list messages by searching.
If you use a regular string,
You can use partial matching as well:
If you prefix the search string with a /, it will search messages' Subject field:
To display a message,
Without a message-list following the
setting, if set),
the headers and body will get sent to your
A lot of headers clutter that output,
so I often use
to winnow these to what I care about.
only those headers I want to see:
Much better. Well, except for the quality of the thesis.
if you subsequently want to see
you can use the
(with a capital "P")
Deleting (and undeleting) messages
command deletes the current message,
undeletes a deleted message.
Both accept a list of message-IDs
Replying to messages
After reading a message,
you can use the
command to reply to all the recipients,
command to reply only to the author of the message.
The section on mail composition has more details on how to edit your reply.
Composing new messages
To compose a new message from within
The section on mail composition has more details on how to compose your message.
Once you have read a message, rather than delete it, you may prefer to file it in a separate mbox archive so it doesn't clutter your main inbox. Use the s/save command to specify an mbox file. You can specify a message-list between the save command and the mbox filename to save multiple messages in one command.
Alternatively, if you would like to save a copy of the message, while keeping the original in the current mailbox, use the c/copy command which has the same syntax as save.
Now you can read mail
from your system mailbox.
And you can file mail in other mbox stores.
How do you access those folders?
You can either specify it on the shell command-line with
or within mail using the
allows you to prefix a folder-name with "+"
to refer to mbox stores in that folder
regardless of your current working-directory.
Additionally, you can use
"%" to refer to your system mailbox,
"#" to refer to the previous folder you had open,
and "&" to refer to your
set folder="mail" copy 8 +thesis folders bills thesis
Mail composition mode
When creating a new message, either via the shell
mail -s "My subj" firstname.lastname@example.org
m email@example.com Subject: My subjectby default
lets you enter your message
one line at time
and terminate it with a period or EOF:
m firstname.lastname@example.org Subject: thesis feedback Thanks for your helpful feedback. .
While convenient to type your message
and send it,
sometimes you want to edit the message
revise the list of recipients,
change the Subject line,
or include a message's contents
for a point-by-point reply.
By entering a message-body line
beginning with a tilde
followed by a command-letter,
or use the
to abandon the message completely.
If you saved a draft,
you can read it back in with
Using ~? will give you the full list of allowed tilde commands.
Use ~t recipient, ~c recipient, and ~b recipient to add recipients to the "To:", "CC:", and "BCC:" recipient-lists respectively. The ~s lets you edit your "Subject:" header. Or use ~h to edit each header in turn.
commands let you edit the current message
When you return from your editor,
you can continue to append to the message where you left off.
To display the message as it currently stands,
As with other mailers,
sometimes you want to include the content of other messages.
commands let you read one or more messages
from your current mailbox
into the current message.
If you omit the
(I recommend the internet standard "> "),
will prefix each line with the corresponding value:
set indentprefix="> " m email@example.com Subject: thesis feedback ~m /thesis Thanks for your helpful feedback. .as commonly used for replies. By default, only the retained headers get included. If you want all the headers, use the uppercase versions ~F & ~M instead.
Alternatively, you might want to read output from an external file (with ~r filename) or command (with ~! command)
Finally, sometimes you want
to pass your message
through an external utility
or a spell-check utility.
command lets you filter the message.
Beware: if editing over
use tilde-escapes at the beginning of the line.
To send a tilde over
you may have to hit
twice to send the tilde to
Not having the best memory,
I prefer to let my computer keep track of contacts.
I want to type "john" as the recipient
and let my mail program figure out who I mean.
Do I want to forget any family members
when sending out important family-wide updates?
The "alias" file contains tuples beginning with the keyword
followed by the nickname you want to use,
and one or more addresses to expand into.
This lets me compose a message to "john" or "family"
file can contain startup commands & settings
to tweak the behavior of
below as an example.
As listed above,
I set my
to a very small subset of headers
that I actually want to see,
$PAGERfor display. Setting
crtlets you override this. For instance, on one machine, I set this 120 lines and commonly read my 3–4 system messages by issuing p * to display all the messages. Any one message falls below that threshold, letting me see an individual message without paging. But I find it handy to read all of them together in
$PAGERin one quick skim.
$HOMEdirectory. If you use the folders command to list available mbox files, it may return lots of non-mbox files. Instead, if you store your mail in a subdirectory, you can set that here. Additionally, regardless of your current working-directory, you can prefix folder-names with a "+" to refer to folders in your
Each time you open a folder
(whether at startup
or using the
When quitting and leaving your system mailbox,
~/mboxby default). By setting
replying to a message,
common convention suggests
that you prefix each quoted line with the string
indentprefixsetting controls this.
This specifies your default "mbox"
local mail store,
~/mboxbut I prefer to set this to a file within my
When sending a message,
often times you want to keep that message around.
recordsetting lets you specify the folder in which to put a copy. Unfortunately, there's no folder-name for the current folder, but you can use something like
+sentto keep them all in the same folder.
Normally when specifying a message-list
by searching with
searchheaders, you can prefix your search term with a header-name to search. This lets you do things like f /To:firstname.lastname@example.org (to search for all messages sent to the dean) or f /Date:Jul (to search for messages sent in July). If you omit the header, it defaults to searching the Subject header as usual.
an excerpt of my
Tips & tricks
Deleting all-but XYZ
I receive a number of messages from system-administration processes. Some come daily, some weekly, some monthly. Some have security advisories, while others give general system information. So I usually want to delete the non-security-related ones. However, the subject lines make this more challenging. The trick? Delete all of them, then undelete the security-related ones:
I can then review these more-relevant messages without the noise of the other messages.
Quickly processing messages
On some machines,
I want to read all the mail in my
to show a screen-full at a time
and then delete all the messages unless
something surprising shows up.
Other times, I want to read each message and process as I go. After displaying a message, I can hit enter (with no command) to display the next message automatically. Alternatively, the dp command will delete the current message and print the next message in one go. It may only save one keypress, but I find it useful