Mail

by Gisle Hannemyr

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

The mail client is a computer program that can be used to access and manage a user's email.

Such a program is also called a mail user agent (MUA) and is the software the end user sees and uses when interacting with his or her email. This software relies on other software such as mail transport agents (MTAs) or protocols such a POP or IMAP that comminicates with mail servers. The latter is only seen and configured by system administrators and is beyond the scope of this beginner's guide.

Mutt

One if the first screen oriented Unix MUAs was named elm. However, elm is no longer maintained and has been replaced by mutt.

Mutt is a descendant of elm and by default, it can be used as a straightforward MUA interacting with a classic (sendmail-based) Unix MTA. However, it can also be set up to be a mail client communicating 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

The user interface of mutt is screen oriented and menu based.

Alpine

An early alternative to elm was named pine (supposedly and acronym for “Program for Internet News and E-mail”). However, pine is no longer maintained and has been replaced by alpine (an acronym for “Alternatively Licensed Program for Internet News and Email”).

It is a mail user agent and client designed to be simple. 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.

You start alpine like this:

$ alpine

If you’ve never used alpine before, you’ll get a welcome message that suggests you start out by configuring alpine.

The user interface of alpine is screen oriented and menu based.

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

Reading mail with Gnu mail

To 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 revisit that list 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:

  1. Message status.
  2. Message number.
  3. Sender.
  4. Date and time.
  5. Lines/Chacters
  6. Subject

The active message is marked with a > as the first character on the line.

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
mutt Send or receive email
alpine Send or receive email
mail Send or receive email
s-nail Send or receive email