Using Unix email clients
This chapter contains information related to some of the mail clients available for use in the CLI in Unix and Gnu/Linux.
Table of contents
Introduction
A mail user agent (MUA) or a mail client is a computer program that can be used by an end user to access and manage a user's email.
A MUA relies on a mail transport agent (MTA) such as Postfix. A mail client uses a protocol (such a POP3 or IMAP) to comminicate with a mail server.
Why should one use CLI email client when a lot of feature rich web-based and PC-based MUAs already exists? Well, as a server administrator, you need to see messages sent to root. Often on a dedicated or VPS hosted service, the operating system will spurn messages to root@localhost if it deems the messages to be important. These critical messages often contain extremely valuable troubleshooting information that will be found nowhere else.
For an overview of MUAs and mail clients, see Wikipedia: Comparison of email clients.
This chapter introduces em>Mutt and Alpine, both allows using arrow keys for navigation, but also allow remote access from GUI email clients using IMAP. There is also some information about using the command driven GNU mail and S-nail.
One important difference between them is that “Mutt”
and “S-nail” let you use the superior
Gnu/Linux Maildir
directory structure to store mail,
while “Alpine” and “GNU mail” uses the legacy
Unix mbox
textfile format.
We currently recommend and provide Mutt by default. However Hannemyr Nye Medier AS will set up other MUAs for clients upon request.
Naming
One if the first screen oriented Unix MUAs was named elm (electronic mail). However, the last release of elm (2.5.8) was in august 2005. It is now replaced by Mutt, which has a user interface similar to elm. An alternative to elm was pine (Program for Internet News and Email). Pine is no longer maintained and has been replaced by alpine (Alternatively Licensed Program for Internet News and Email).
Alpine
Alpine is designed to be simple to learn and use. It can be used as MUA interacting with a classic Unix MTA, or as a mail client communicating with a mail server by means of POP3 and IMAP.
The user interface of Alpine is screen oriented and menu based. It provides a rich set of shortcut keys.
You start alpine like this:
$ alpine
GNU mail
The GNU mailutils package that is installed by default on many Gnu/Linux distribution includes an enhanced version of standard Unix mail program. It is command line oriented.
Here is an example of using the CLI to send a message with the subject “Hello” to “user@example.com”:
$ echo "This goes into the mail body." | mail -s "Hello" user@example.com
It uses the legacy Unix mbox
textfile format to store mail.
Gnu mail commands
To use the MUA, open a mailbox in reading mode:
$ mail -f ?
The question mark is the prompt from GNU mail, and tells you that you're running the mail program and not the shell. Any command you type after this point will affect your mailbox.
To see a list over the commands available in GNU mail program, you can type “help”. Example:
? help mail commands type <message list> type messages next goto and type next message from <message list> give head lines of messages headers print out active message headers delete <message list> delete messages undelete <message list> undelete messages save <message list> folder append messages to folder and mark as saved copy <message list> folder append messages to folder without marking them write <message list> file append message texts to file, save attachments preserve <message list> keep incoming messages in mailbox even if saved Reply <message list> reply to message senders reply <message list> reply to message senders and all recipients mail addresses mail to specific recipients file folder change to another folder quit quit and apply changes to folder xit quit and discard changes made to folder ! shell escape cd <directory> chdir to directory or home if none given list list names of all available commands A <message list> consists of integers, ranges of same, or other criteria separated by spaces. If omitted, mail uses the last message typed. ?
To quit the mail program, apply any changes made to the mailbox, and return to the shell, type “quit”.
? quit $
When you start Gnu mail in reading mode, it will list all the headers in the mailbox. You can get that list again with the command “header”. To see a specific message, use the command “type” followed by the message number. Example:
$ mail -f O 1 barney@example.com Tue Aug 27 11:59 54/2066 Just testing the mail system >U 2 Fred Flint Tue Aug 27 13:44 17/630 Invitation to a BBQ ? type 2 Message 2: From fred@example.com Tue Aug 27 13:44:23 2013 … Status: RO There will be a barbecue in our back yard tonight. Please come! -- Fred Flint ? headers O 1 barney@example.com Tue Aug 27 11:59 54/2066 Just testing the mail system >O 2 Fred Flint Tue Aug 27 13:44 17/630 Invitation to a BBQ ?
The header list shows the following six fields from left to right:
- Message status.
- Message number.
- Sender.
- Date and time.
- Lines/Chacters
- Subject
The active message is marked with a >
as the first character on the line.
Mutt
Mutt can be used as a straightforward MUA interacting with a classic (sendmail-based) Unix MTA. However, it can also be set up as a mail client to to communicate with a mail server by means of POP3 or IMAP.
By default, it has an interface similar to elm. However it has a much larger repetoire with hundreds of configuration directives and commands. It allows for changing all the key bindings and making keyboard macros for complex actions, as well as the colors and the layout of most of the interface.
It also supports modern mail extensions, such as MIME and PGP.
You start mutt like this:
$ mutt
Using Mutt
The user interface of mutt is screen oriented and menu based.
The messages are numbered. To jump to a specific message, type the number.
Bulk deleting mail with Mutt
System generated error and other message sent to Mutt will build up over time. If you don't log in regularly and clean up, you will end up with thousands of messages eventually, taking up lot of disk space.
To delete all messages, start mutt, and
press SHIFT+D
. Then at in the status bar (at the bottom
of the screen should show) type "~s .*
". I.e.:
Delete messages matching: ~s .*
Press ENTER
, followed by q
(to quit), and then d
to confirm deletion
S-nail
S-nail is a variant of the BSD mailx client, often used with the Postfix MTA. It is command line oriented. It is also usable as a mail batch language, both for sending and receiving mail.
Unlike Gnu mail, it can handle
the Maildir
-format directly. In this format, mail is
kept in a director direcory named Maildir
in the user's
home directory.
Here is an example of using the CLI to send a message with the subject “Hello” to “user@example.com”:
$ echo "This goes into the mail body." | s-nail -s "Hello" user@example.com
Reading mail with s-nail
To open a mailbox in reading mode:
$ s-nail s-nail version v14.9.6. Type ? for help. "/home/username/Maildir": 1 message 1 new >N 1 User Name 2018-10-23 87/5043 This is a test
Just hitting [Enter]
should display the new message.
To see a list over the commands available in s-nail program, you can type “?” or “help” when you see the “?” prompt. Most commands can be abbreviated to a single character.
h : list headers t 1 : type message #1 d : delete current message q : quit (save changes) x : disregard changes
Summary
Command | Meaning |
---|---|
alpine |
Send or receive email |
mail |
Send or receive email |
mutt |
Send or receive email |
s-nail |
Send or receive email |