Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Find the answer to your Linux question:
Site Navigation
Linux Forums
Linux Articles
Product Showcase
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds
Free Publications

Despite the plethora of email clients available nowadays, the text basedmutt is still the choice of many gurus. It follows the Unix philosophyof doing one thing well rather than trying to do many things.
Although there is limited POP3 functionality, and muttng even has the ability to use builtin SMTP, in general, experts use mutt to read the mail and other programs to send, receive and filter. Despite this, mutt can do a great many things. People used to graphical email clients will be surprised at its abilities.

This article will show you how to get started with mutt, using ssmtp to send mail, getmail to receive it and maildrop to filter it. It will only introduce you to mutt, but hopefully, it will let you begin to explore mutt's potential.

In our example, your username on the machine will be john. You have an email account with example.net, john@example.net. Your user name with the ISP is john and your password is 1234. Your ISP has a pop server called pop.example.net and an smtp server named smtp.example.net. Your home machine is called john.mydomain.com.

As there are so many different Linux distributions, each with their own way of doing things, in this case, we are going to assume that packages are put into /usr. Therefore, I will be using the path of /usr/bin and /usr/sbin. Your distribution may do things differently. This can always be checked by the which command. For example, after installing getmail you can type

which getmail

If it returns an answer of /usr/bin/getmail, then use the example I give you. If it returns, for example, /usr/local/bin/getmail, then when I type /usr/bin/getmail, substitute /usr/local/bin/getmail. This applies for any of the programs where I give their path in a command.

Configuring ssmtp

We'll start with ssmtp. Most distributions have a package available, however if your distribution doesn't, you can download the source code from Debian's site.

It will install a configuration file in /etc/ or perhaps /usr/local/etc called ssmtp.conf or ssmtp.conf.sample. If it's called sample, then copy it to a file in the same location, calling the new file ssmtp.conf. (In some distributions, it will put the file into its own directory, for example, /etc/ssmtp/ssmtp.conf)

One of the first lines reads


You may want to change this to john@example.net, especially if you are going to be using ssmtp as a replacement for sendmail, postfix, exim or whatever your distribution uses as its MTA. (Mail Transport Agent.) Doing that is beyond the scope of this article, but you can see this article on ssmtp for more details.

The next line to change is the line for your mailhub. This is your ISP's SMTP server, so in our example, we want it to read


We will change the rewriteDomain name to give our ISP's domain.


The hostname is the machine's hostname


Uncomment, by removing the #, the FromLineOverride.


That's all that has to be done. Now, let's look at getmail.

Configuring getmail

Getmail is available as a package on most distributions. If it isn't, the latest version's source code can be found at its home page.

Getmail does require that python be installed. If you have to install it from source, the instructions are in its README file. If you have to build from source, do the following, (This assumes python is installed. If it isn't, install python first. This example uses getmail-4.5.3, the current version at time of writing, change it to the version you download)

tar -xzf getmail-4.5.3.tar.gz cd getmail-4.5.3 python setup.py build python setup.py install

The setup.py install line will have to be run as root or with root privilege.

Getmail will install some documentation, including sample configuration files. In this case, we are making a very simple file. We want getmail to fetch mail from our pop.example.net server and put it in $HOME/Mail/inbox. We will be using the default mutt mbox format. Create a $HOME/.getmail directory, open your favorite text editor and create a getmailrc file.

[options] verbose = 0 delete = True [retriever] type = SimplePOP3Retriever server = pop.example.net username = john password = 1234 [destination] type = Mboxrd path = ~/Mail/inbox

For the newcomer to Linux and other Unix like systems, note that your home directory will often be called $HOME or simply referred to with a tilde, ~. So, /home/john can be called ~ or $HOME.

After configuring mutt, we'll have getmail automatically poll for mail every 5 minutes, but first, let's get mutt up and running.

We create our $HOME/Mail directory and the inbox.

mkdir ~/Mail touch ~/Mail/inbox

Configuring Mutt

Now it's time to configure mutt. There is usually a system wide configuration file with reasonable defaults, however we will want to do a bit of customization. Once again, open your favorite text editor and create a $HOME/.muttrc file.

set folder="~/Mail" set sendmail="/usr/sbin/ssmtp" set from="John john@example.net;" fcc-hook ~/Mail/SENT macro index G "!getmail -vn" "Invoke getmail"

We have set the main directory for incoming mail to be ~/Mail. (This one is usually already set by default in your systemwide muttrc, but it won't hurt anything.) Mutt now knows to use ssmtp to send mail. (See my note at the beginning of the article about checking a program's path.) The from line indicates what will appear in the From: line. You can use John, John Smith, Unix guru or whatever you would like it to read. The fcc-hook indicates that sent mail will go into ~/Mail/SENT. You don't have to create the SENT mailbox, it will be created the first time you send mail.

Lastly the macro index line means that you can always fetch your mail by hitting shift+G while in mutt.

All the elements are now in place. Open mutt by simply typing mutt at a command prompt. You will get a harmless but annoying error message that there is no /var/mail/john. (Depending upon distro and O/S, it might be /var/spool/mail/john.) To get rid of the message, as root or with root privilege, create the file. In this case, we'll assume it's /var/mail/john

touch /var/mail/john chown john:john /var/mail/john chmod 600 /var/mail/john

When mutt opens, you will see a line at the top with some keyboard shortcuts and and a line at the bottom, usually saying something like --mutt: /var/mail/john [Msgs:0]. Send a test email to yourself. After opening mutt, hit m as in mail.

A To: field will appear. Fill it in, john@example.net. Then, it will ask for a subject, so put in test. (If you don't put in a subject, it will ask if it should abort, with a default of yes.)

After putting in the subject, an editor will open, usually vi. It uses the default system editor. If you are more comfortable with nano, it can be specified. Open .muttrc and add a line

set editor="/usr/bin/nano"

In the body of the message, write whatever you wish. Save and close--in vi you would use :wq or :x. You will then see a screen showing the headers of your mail (From, To, etc). To send the message, hit y. If all goes well, you should see that the message is sent.

Hit shift+G to invoke getmail. In .muttrc it was set to use the -v for verbose flag, so you should see it connecting to pop.example.net and getting the message. Press c (as in change) and a message will appear

Open mailbox ('?' for list):

Hitting ? will then show you ~/Mail/inbox. If it isn't highlighted, you can use the arrow keys or vi commands (k for upward momvement, j for downward) to highlight it. Then, hit enter and you can read your mail.

As promised above, we now set getmail to automatically check for mail. The easiest way to do this is with cron. Type

crontab -e

This opens up an empty editor, allowing you to edit your crontab. To set getmail to run every five minutes type

*/5 * * * * /usr/bin/getmail

While man(5) crontab gives a more detailed explanation, in brief, we are telling crontab to run getmail every five minutes. It's important to put the full path to getmail in there.

Save and close the file, and you'll see a message that a new crontab is being installed.

Mutt can now be used to send and receive mail, but no doubt, you would like to do some basic filtering. We're going to use maildrop.

Although it might not be installed by default, maildrop is available with most distributions.

Using maildrop

In our example, john belongs to 2 mailing lists called list1 and list2. Everything else can go into the Mail/inbox. Maildrop will create the mailboxes when an email from one of these lists arrives, so we can skip that part.

Open your favorite text editor and create a $HOME/.mailfilter file. If you have SpamAssassin installed, you probably want to run everything received through that first.

#Run everything through SpamAssassin xfilter "/usr/bin/spamassassin" if (/^X-Spam-Level: ****/) to Mail/Spam if (/^To: .*list1/) to Mail/list1 if (/^To: .*list2/) to Mail/list2 DEFAULT="Mail/inbox"

Mailfilter is quite flexible. With some mailing lists, the To: line might not contain the pattern "list1." The list1 pattern might be in the cc, reply-to or bcc line. In that case, one can use multiple patterns

if (/^(From|To|Reply-to|bcc): .*list1/) to Mail/list1

Hopefully, the examples make the pattern clear. The search pattern is (/^pattern/). If you have multiple patterns, then you need a second set of parentheses, separating the patterns with pipes. One can use From, To, Subject, etc.

The $HOME/.mailfilter file should not have group or world permissions, so we want to make sure that its permissions are correct.

chmod 700 ~/.mailfilter

Now that we have maildrop ready for use, we'll change our ~/.getmail/getmailrc file to make use of it. We're going to change the destination section. Now, we want it to read

[destination] type = MDA_external path = /usr/bin/maildrop unixfrom = True

As stated in the beginning, this article is merely an introduction, not only to mutt, but also to the other programs we're using, ssmtp, getmail and maildrop. Although ssmtp only has a somewhat sparse man page, the other programs all have extensive documentation, usually installed with the program in /usr/share/doc.

The mutt site's documentation section has links to online versions of the manual for different versions, as well as a wiki. The interested reader can find a great deal of information there.

Rate This Article: poor excellent
Comments about this article
pop checker?
writen by: Anonymous on 2006-03-02 09:19:12
It may sound odd or backward, but I've become accustomed to using my email client as a sort of glorified pop checker. I use Pine, and it does pretty much what I need. I'm wondering if Mutt might be an enhancement. Here's the scheme: I tell Pine to show me all messages on the server without downloading them. I can read them as they sit there on the server, respond, or delete spam. Then I close the mailbox and check the next one (3 or 4 accts). I basically leave all mail there until a certain amount accumulates, at which point I download it en masse to my machine. I've become accustomed to this way of dealing with mail, and would prefer to stick with it. I know Mutt does pop checking, since I've used it to do that. What kept me from trying it so far is its smtp inabilites combined with my lack of time to learn to configure exim or the like. I gather from this article that this would no longer inhibit. But can it be made to pop-check as easily as Pine? Must one enter c pop://my.pop.server every time to have it pop check, or is there some way it could be configured to remember my various pop server addy's?
RE: pop checker? written by Anonymous:

Comment title: * please do not put your response text here