Mail (mutt, fetchmail, procmail, msmtp)

Today, we will see how to get mails, read them, and answer them, inside a terminal. We will need four utilities for that :

  • one to fetch the mails on the server : fetchmail,
  • one for processing the mails once they are received : procmail,
  • a mail client for viewing them : we will choose mutt
  • an agent for sending mails : msmtpis a good choice (or sendmail, which should be installed by default on most Linux and BSD distribution )

Install each of this utilities according to the usual way of your distribution. The following tutorial assumes you have two accounts : and, account1 being the main account. Do not forget to change it to your needs !

Note : you will have to rename the config files downloaded from here. For example, “fetchmailrc” will become “.fetchmailrc”.


First, we need to fetch the mails from the server. Write a configuration file similar to mine :

Here is a configuration for two accounts so you can manage multiple configurations. You also have an example of fetching subfolders and using SSL certificates.

Then change the permissions:

Now comment the line containing set daemon and start it in verbose mode

If everything looks good, you can uncomment the daemon mode and let it fetch new mail every minute with

set daemon 60 


The role of procmail is to filter your mail. The idea is to put all mails sent to account2 in corresponding mailbox, and the rest to the box of account1 (it is supposed to be your main account).

For that, you will need to create a mailbox. We will use the Maildir format. For example, if ~/Mail is you mail directory, we will create a folder named account1 containing three folders : cur, tmp, new. Do the same for account2.

Then, create your configuration, following mine :

Several things to note here. First, we must deliver mail into the New folder. Then we can use rules to put mail into several folders (here, it’s Horse or Turtle). But it can also be used for filtering spam ! See the procmail documentation for that.


In the .msmptrc file, we are going to specify two accounts. On of them will be the default, as in my file :

Note : Gmail can be picky about the certificate. Using the Equifax certificate of your distribution is the safest way (see the configuration file for the path). Otherwise, you can try :

Change the permissions :

Then, you can try sending mail with the following command :

where test.mail is an simple file like this one :

Subject: Test <br/> 

Hello !

Beware, there must be an empty line after the Subject.


Finally, our mail client ! Mutt is powerful and highly configurable. For more details, see the official documentation.

My config file can be grabbed here. It is pretty much commented so I will only explain the configuration about managing several accounts and folders.

Mutt does not know of any account, just of folders, which may potentially be mailbox. So we receive our mail in the spoolfile by default.

Mutt cannot move automatically mail to other folders (no, really, it cannot). So we are left with two solutions : either create a macro which will invoke procmail to filter mail or use Mutt’s command. I did not try the first solution as the second is easiest.

Basically, you define rules for moving files (see the .muttrc) with save-hook. When you have read your file, press s and a mailbox will be suggested. If your rules are correct, you just need to press Enter. Then, you can change mailboxes with c or … see the next section.

Finally, you can define a mail associated to a mailbox with :

In my .muttrc, you will see shortcuts for switching between the two accounts. Feel free to change them.

Now, let us test the awesomeness of mutt. For example, start mutt. The first time, we need to start fetchmail manually with f (cf my .muttrc). You should have received all your new mails by now.

If you want to search a mail, use /. For reading a mail, just select it with Enter. Adding the sender to you alias is done with a. Answer him (or her) with r.

Type your reply (with ViM for example) and send it with y. Congratulations you can now use Mutt in your everyday life ! If you want to see all the shortcuts, help is available with ?.


Following on the question of folders, there is an Mutt extension, called mutt-patched, which displays mailboxes on a separate window. For that, you need to install it and set :

Please note the mailbox must be defined as subfolder of your main folder. So it must be :