Mutt

From SlackWiki
Jump to navigation Jump to search

Mutt

Mutt is a text-based mail client renowned for its powerful features and the fact that it is almost totally customizable. This article will cover the installation and configuration of mutt in order to use it as your daily email client. Please note that I use GMail as my primary email address, so the examples are designed for GMail users. Not much differs though other than the fact that GMail uses SSL.


Installation

Slackware comes with a package for mutt v1.4. If you did a full install, you already have it installed. If not, it can be located on the 'n' series on your Slackware install CD or favourite mirror. This tutorial also uses getmail, procmail and msmtp. procmail and getmail are available as Slackware packages, and can be installed in the same manner...

If you have the CD, follow these steps as root to install it:

 mount /mnt/cdrom
 installpkg /mnt/cdrom/slackware/n/mutt-1.4.2.1i-i486-2.tgz
 installpkg /mnt/cdrom/slackware/n/getmail-4.4.4-noarch-1.tgz
 installpkg /mnt/cdrom/slackware/n/procmail-3.22-i486-1.tgz

If you would rather install it from a mirror:

 wget http://www.slackware.at/data/slackware-current/slackware/n/mutt-1.4.2.1i-i486-2.tgz
 wget http://www.slackware.at/data/slackware-current/slackware/n/getmail-4.4.4-noarch-1.tgz
 wget http://www.slackware.at/data/slackware-current/slackware/n/procmail-3.22-i486-1.tgz
 installpkg mutt-1.4.2.1i-i486-2.tgz getmail-4.4.4-noarch-1.tgz procmail-3.22-i486-1.tgz

Be sure to replace 'slackware-current' with the actual version of Slackware you are using.

msmtp is not part of Slackware, and will need to be installed separately. It can be downloaded from here. If you need information on building Slackware packages, click Building_A_Package for an excellent tutorial.

Configuration

Mutt

First, let start with mutt, and a very simple ~/.muttrc:

# Name
set realname='Slackware User'

# Where we store our emails
set folder=~/mail
set mbox=+mbox
set spoolfile=+inbox
set record=+sent
set sort=threads # sort by emails by thread ;-)
set postponed=+drafts
set mbox_type=Maildir 
mailboxes +inbox

# my favourite editor is 'joe'
set editor=joe

ignore *	# this means "ignore all headers by default"
# I still want to see some basic details
unignore	date from subject to cc

# Mutt options
set edit_headers=yes
set hdrs # Allows us to create our own headers
my_hdr From: Slackware User <user@slackware.com>
my_hdr X-Mailer: `mutt -v| head -n 1`

So far, it's simple, and cannot do much. We can almost read emails stored in ~/mail, compose and save drafts.

In order for us to read emails, first, we need to create our mail folders. We are using the Maildir format, so we need to create them using:

mkdir -p ~/mail/inbox/{,cur,tmp,new}
mkdir -p ~/mail/sent/{,cur,tmp,new}
mkdir -p ~/mail/drafts/{,cur,tmp,new}

Now, when we have an email in ~/mail/inbox, we will be able to read it. Postponed messages will also be saved in ~/mail/drafts. But want to be able to send emails too, right? That's where msmtp comes into play.

For this part, we will assume that msmtp is installed. msmtp is basically a SMTP client that will be called by mutt when sending an email. So we need to have added to the mutt config like this:

set sendmail="/usr/bin/msmtp"

Now, that's useless by itself. We need to setup msmtp to send emails... Open up ~/.msmtprc with your favourite editor. This is a copy of mine, setup to use GMail's smtp server:

account default
host smtp.gmail.com
port 587
protocol smtp
auth on
from username@gmail.com
user username@gmail.com
password mypassword
tls on
tls_starttls on


So, after going through this and identifying what we need for our SMTP server, we are ready to send emails... Let's test it:

Launch mutt by running:

mutt -y

Running mutt without '-y' will ignore our mailboxes statement, so we won't see any emails...

You can see in mutt the key shortcuts at the top of the screen: 'm' for composing a new message. After we save the message, we see a new shortcut at the top: 'y' to send the message.

We now have mutt that can read emails from ~/mail/inbox, and send emails!!! The next step is to get the emails in ~/mail, and that's getmail's job.

Getmail

Getmail is a Python application that's included with Slackware. Similar to fetchmail, many people prefer it, saying it's easier to configure. Just like mutt, getmail is in the 'n' series, and should already be installed if you chose to do a full install. If not, just check out the mutt section above to install what's needed for this tutorial.

Once we have it all installed, let's create a basic getmail configuration. This configuration sits in ~/.getmail/getmailrc:

[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = username@gmail.com
port = 995
password = password

[destination]
type = Maildir
path = ~/mail/inbox

If you use a standard POP3 account that doesn't use SSL, use something like:

[retriever]
type = SimplePOP3Retriever
server = pop.isp.net
username = username
port = 110
password = password

[destination]
type = Maildir
path = ~/mail/inbox

If you use Gmail's IMAP account, use something like:

[retriever]
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
username = username
password = password

[destination]
type = Maildir
path = ~/mail/inbox


As simple as that. Now, it will connect to your email account, and download all your emails to ~/mail/inbox. Please note that if you want to fetch mail for multiple accounts, unlike fetchmail, getmail works with a single account per config file. So if you have two email accounts, you can have each account configured in their own config file like ~/.getmail/getmailrc and ~/.getmail/getmailrc-isp

If you want automatic check, just add the following lines to your crontab by running crontab -e for each one of your email accounts:

/5 * * * * /usr/bin/getmail
/30 * * * * /usr/bin/getmail -r ~/.getmail/getmailrc-isp

Procmail

Procmail is an advanced mail filtering solution. More to come

Todo

The rest...