Mutt

From ArchWiki

Jump to: navigation, search
i18n
English
Italiano
正體中文
简体中文

Mutt is a text-based mail client renowned for its powerful features. Mutt, though over a decade old, remains the mail client of choice for great number of power-users. Unfortunately, a default mutt install is plagued by complex keybindings, and a daunting amount of documentation. This guide will help the average user get mutt up and running, and begin customizing as deemed fit.

Contents

Quick Start

What Mutt Does Not Do

Mutt is a Mail User Agent (MUA), and was written to view mail. It was not written to retrieve, send, or filter mail. It relies on external programs to do those tasks. For this wiki, we will be using offlineimap or getmail to retrieve our mail, procmail to filter our mail in the case of POP3, and msmtp to send our mail.

However, the Arch official binary package of mutt has been compiled with IMAP, POP and SMTP support, and thus does not need external programs to retrieve and send mails any more.

Optional: Auth CRAM-MD5 et al.

If you just need the authentication methods LOGIN and PLAIN, these are satisfied with the dependency libsasl. If you want to (or have to) use CRAM-MD5, GSSAPI or DIGEST-MD5, install also the package cyrus-sasl-plugins, and you're done.

Note: if you are using gmail as your smtp server, you will need to install the package cyrus-sasl.

Setting up IMAP

Using native IMAP support

The pacman version of Mutt is compiled with IMAP support. At the very least you need to have 4 lines in your muttrc file to be able to access your mail.

spoolfile

Instead of a local mail spool, specify imap server.

set spoolfile=imap[s]://imap.server.domain[:port]/folder

Use imaps for ssl, imap for no encryption. The port number is only needed when your server's port is non-standard. End with the folder name where new mail arrives, which is almost always INBOX. Example:

set spoolfile=imaps://imap.gmail.com/INBOX

imap_user

set imap_user=USERNAME

Continuing with the previous example, remember that gmail requires your full email address (this is not standard):

set imap_user=your.username@gmail.com

folder

Instead of a local directory which contains all your mail (and directories), use your server (and the highest folder in the hierarchy, if needed).

set folder=imap[s]://imap.server.domain[:port]/[folder/]

You don't have to use a folder, but it might be convenient if you have all your other folders inside your INBOX, for example. Whatever you set here as your folder can be accessed later in Mutt with just an equal sign (=). Example:

set folder=imaps://imap.gmail.com/

mailboxes

Any imap folders that should be checked regularly for new mail should be listed here (all on the same line).

mailboxes <list of folders>

You can now use '=' which will be filled in with whatever folder was set to. For example:

mailboxes =INBOX =family
mailboxes imaps://imap.gmail.com/INBOX imaps://imap.gmail.com/family

These two versions are equivalent, but the first is much more convenient. Also, Mutt is configured by default to include a macro bound to the 'y' key which will allow you to change to any of the folders listed under mailboxes.

Summary

Using these options, you'll be able to start mutt, enter your imap password, and start reading your imap mail. Here is muttrc snippet (for gmail) with some other lines you might consider adding to your muttrc file for better imap support.

set spoolfile=imaps://imap.gmail.com/INBOX
set imap_user=your.username@gmail.com
set folder=imaps://imap.gmail.com/
mailboxes =INBOX

# store message headers locally to speed things up
set header_cache=~/.mutt/hcache

# specify where to save and/or look for postponed messages
#set postponed=imap[s]://imap.server.domain[:port]/<drafts_folder>
# or
#set postponed==<drafts_folder>
set postponed==[Gmail]/Drafts

# allow mutt to open new imap connection automattically
set imap_passive=no

# keep imap connection alive by polling intermittently (time in seconds)
set imap_keepalive=300

# how often to check for new mail (time in seconds)
set mail_check=120

External IMAP Support

While IMAP-functionality is built into mutt, it does not download the Mail for offline-use. This section describes how to download your emails with OfflineIMAP to a local folder which is then processed by mutt.

Setting up OfflineIMAP

First, enable the community-repository and install OfflineIMAP via a simple pacman -Sy offlineimap. You now need to set it up for your special needs. Create the file ~/.offlineimaprc and edit it with your favorite editor. I will now show you a sample-configuration. Edit according to your special needs, but take care that comments are placed on their own separate line: placing a comment after an option/value on the same line will cause errors!

[general]
# change to whatever you want:
accounts = myaccount 

# Gives you a nice blinky output on the console so you know what's happening:
ui = Curses.Blinkenlights 

# If uncommented, this would show nothing at all. Great for cronjobs or background-processes:
# ui = Noninteractive.Quiet 

[Account myaccount]
# Profile-Name for the local Mails for a given Account
localrepository = mylocal 

# Profile-Name for the remote Mails for a given Account
remoterepository = myremote 

# fetches your mails every 5 Minutes
autorefresh = 5 

[Repository mylocal]
# Way of storing Mails locally. Only Maildir is currently supported:
type = Maildir 

# Place where the synced Mails should be:
localfolders = ~/Mail 

[Repository myremote]
# Type of remote Mailbox. Only IMAP is supported right now:
type = IMAP 

# Where to connect:
remotehost = imap.myhost.com 

# Whether to use SSL or not:
ssl = yes 

# Would specify a port if uncommented. This way, it just tries to use a default-port:
# remoteport = 993 

# Specify login-name:
remoteuser = myremoteusername 

# Specify login-password (there are other/safer options for storing passwords for use by OfflineIMAP,
# see the OfflineIMAP manual. Make sure that ~/.offlineimaprc is readable only by you, if you 
# specify your password here!): 
remotepass = myremotepassword

This is a minimal setup to get you going. For more advanced features, consult the OfflineIMAP Homepage and check back at the annotated offlineimaprc.

You are now almost ready to run OfflineIMAP. Create the directory you have defined in the offlineimaprc, in this case via mkdir ~/Mail. Then run offlineimap. Your eMails will now be synced. If anything goes wrong, take a closer look at the Error-Message. OfflineIMAP is usually very verbose about problems.

Configuring mutt for MailDir

The beauty of MailDir is, that it is a generic and standardized format. Almost every MUA is able to handle MailDirs and mutts support is excellent. There are just a few simple things that you need to do to get mutt to use them. Open your muttrc with your favorite editor and add the following lines.

set mbox_type=Maildir
set folder=$HOME/Mail
set spoolfile=+/INBOX
set header_cache=~/.hcache

This is a minimal Configuration that enables you to access your Maildir and checks for new local Mails in INBOX. This configuration also caches the headers of the eMails to speed up directory-listings. It might not be enabled in your build (but it sure is in the Arch-Package) Note that this does affect OfflineIMAP in any way. It always syncs the all directories on a Server. spoolfile tells mutt which local directories to poll for new Mail. You might want to add more Spoolfiles (for example the Directories of Mailing-Lists) and maybe other things. But this is subject to the mutt-Manual and beyond the scope of this document.

That's it. Don't forget to adjust everything to your liking. Get cracking!

Setting up for POP mail

Retrieving Mail

First install getmail. It is in the [extra] repository.

 pacman -S getmail

Now create the directory ~/.getmail/. Open the file ~/.getmail/getmailrc in your favorite text editor.

Here is an example getmailrc used with a gmail account.

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

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

You can tweak this to your POP3 service's specification.

For this guide we will be storing our mail in the maildir format. The two main mailbox formats are mbox and maildir. The main difference between the two is that mbox is one file, with all of your mails and their headers stored in it, whereas a maildir is a directory tree. Each mail is its own file, which will often speed things up.

A maildir is just a folder with the folders cur, new and tmp in it.

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

Now, run getmail. If it works fine, you can create a cronjob for getmail to run every n hours/minutes. Type crontab -e to edit cronjobs, and enter the following:

 */30 * * * * /usr/bin/getmail

That will run getmail every 30 minutes.

Sorting Mail

Procmail is an extremely powerful sorting tool. For the purposes of this wiki, we will do some primitive sorting to get started.

First, install procmail. It is in the [extra] repository.

 pacman -S procmail

You must edit your getmailrc to pass retrieved mail to procmail.

[destination]
type = MDA_external
path = /usr/bin/procmail

Now, open up .procmailrc in your favorite editor. The following will sort all mail from the happy-kangaroos mailing list, and all mail from your lovey-dovey friend in their own maildirs.

MAILDIR=$HOME/mail
DEFAULT=$MAILDIR/inbox/
LOGFILE=$MAILDIR/log

:0:
* ^To: happy-kangaroos@nicehost.com
happy-kangaroos/

:0:
* ^From: loveydovey@iheartyou.net
lovey-dovey/

After you've saved your .procmailrc, run getmail and see if procmail succeeds in sorting your mail into the appropriate directories.

NOTE: One easy to make mistake with .procmailrc is the permission. procmail require it to have permission 644 and won't give meaningless error message if you don't.

Setting up for SMTP

Whether you use POP or IMAP to receive mail you will probably still send mail using SMTP.

Using native SMTP support

The pacman version of Mutt is also compiled with SMTP support. Just check the online manual muttrc, or man muttrc for more information.

For example:

set my_pass='mysecretpass'
set my_user=myname@gmail.com

set smtp_url=smtps://$my_user:$my_pass@smtp.gmail.com
set ssl_force_tls = yes

External SMTP Support

Set up a smtp client, for example : Msmtp

Now mutt must be configured to use msmtp. Make a directory ~/.mutt/, and open up ~/.mutt/muttrc. The following should get you started viewing and sending mail.

set realname='Disgruntled Kangaroo'

set sendmail="/usr/bin/msmtp"

set edit_headers=yes
set folder=~/mail
set mbox=+mbox
set spoolfile=+inbox
set record=+sent
set postponed=+drafts
set mbox_type=Maildir

mailboxes +inbox +lovey-dovey +happy-kangaroos

Now, startup mutt. You should see all the mail in ~/mail/inbox. Press m to compose mail (it will use the editor defined by your EDITOR environment variable. If this variable is not set, type export EDITOR=/path/to/yourfavorite/editor. For testing purposes, address the letter to yourself. After you have written the lovely letter, use your editor's save and exit command. You will return to mutt, which will show you information about your e-mail. Press y to send it. If everything works, congratulations! You can use mutt! However, realizing the true power of mutt comes with much customizing.

Customizing Mutt

Guides to get you started with using & customizing mutt :

If you have any mutt specific questions, feel free to ask in the irc channel.

Printing

You can install muttprint http://aur.archlinux.org/packages.php?ID=3122 for a fancier printing quality. In your .muttrc file, insert:

set print_command="/usr/bin/muttprint %s -p {PrinterName}"

Signature Block

Create a .signature in your home directory. Your signature will be appended at the end of your email.

Viewing URLs & Opening Firefox

Your should start by creating a ./mutt directory in $HOME if not done yet. There, create a file named macros. Insert the following:

 macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'

Then install urlview with

pacman -S urlview

Create a .urlview in $HOME and insert the following:

REGEXP (((http|https|ftp|gopher)|mailto)[.:][^ >"\t]*|www\.[-a-z0-9.]+)[^ .,;\t>">\):]
COMMAND firefox %s 

When you read an email on the pager, hitting ctrl+b will list all the urls from the email. Navigate up or down with arrow keys and hit enter on the desired url. Firefox will start and go to the selected site.

  • Note - urlview has been moved to unsupported and is available in AUR here[1]
  • Note - If you have some problems with urlview due to mutt's url encoding you can try extract_url.pl

Mutt and Vim

To limit the width of text to 72 characters, edit your .vimrc file and add:

au BufRead /tmp/mutt-* set tw=72

so, this Vim behavior will occur only when you use it together with mutt.

To set a different temp directory, e.g. ~/.tmp, add a line to your .muttrc as follows:

set tmpdir="~/.tmp"

To reformat a modified text see the Vim context help

:h 10.7

Viewing html within a Vim/Mutt setup

This setup will pass the html body to lynx and then dump it in Vim, keeping email viewing uniform and unobtrusive. Install lynx.

pacman -Sy lynx

If ~/.mutt/mailcap does not exist you will need to create it and save the following to it.

text/html; lynx -dump %s; nametemplate=%s.html; copiousoutput

Edit ~/.muttrc and add the following,

set mailcap_path 	= ~/.mutt/mailcap

The beauty of this is, instead of seeing an html body as source or being opened by a seperate program, in this case lynx, it gets parsed to Vim as html, any url links within the email can be displayed with Ctrl+b.

Mutt and GNU nano

nano is another nice console editor to use with mutt. To limit the width of text to 72 characters, edit your .nanorc file and add:

 set fill 72

Also, in .muttrc file, you can specify the line to start editing so that you will skip the mail header:

 set editor="nano +7"

Additional Resources

Personal tools