Difference between revisions of "Mutt"

From ArchWiki
Jump to navigation Jump to search
m (Typo fix)
m (Typo)
Line 643: Line 643:
===Request IMAP mail retrieval manually===
===Request IMAP mail retrieval manually===
If you do not want to wait for the next automatic IMAP fetching (or if you did no enable it), you might want to fetch mails manually.
If you do not want to wait for the next automatic IMAP fetching (or if you did not enable it), you might want to fetch mails manually.
There is a mutt command {{ic|imap-fetch-mail}} for that.
There is a mutt command {{ic|imap-fetch-mail}} for that.
Alternatively, you could bind it to a key:
Alternatively, you could bind it to a key:

Revision as of 20:00, 28 August 2012

zh-CN:Mutt zh-TW:Mutt Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary end

Mutt is a text-based mail client renowned for its powerful features. Though over a decade old, Mutt remains the mail client of choice for a great number of power-users. Unfortunately, a default Mutt install is plagued by complex keybindings along with a daunting amount of documentation. This guide will help the average user get Mutt up and running, and begin customizing it to their particular needs.


Mutt focuses primarily on being a Mail User Agent (MUA), and was originally written to view mail. Later implementations added for retrieval, sending, and filtering mail are simplistic compared to other mail applications and, as such, users may wish to use external applications to extend Mutt's capabilities.

Nevertheless, the Arch Linux mutt package is compiled with IMAP, POP3 and SMTP support, removing the necessity for external applications.

This article covers using both native IMAP sending and retrieval, and a setup depending on OfflineIMAP or getmail (POP3) to retrieve mail, procmail to filter it in the case of POP3, and msmtp to send it.


Install mutt, available in the Official Repositories.

Optionally install external helper applications for an IMAP setup, such as offlineimap and msmtp.

Or (if using POP3) getmail or fdm and procmail.

  • 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 the package cyrus-sasl-gssapi
  • If you are using Gmail as your SMTP server, you may need to install the package cyrus-sasl


This section covers IMAP, #POP3, #Maildir and #SMTP configuration.

Note that Mutt will recognize two locations for its configuration file; ~/.muttrc and ~/.mutt/muttrc. Either location will work. You should also know some prerequisite for Mutt configuration. Its syntax is very close the Bourne Shell. For example, you can get the content of another config file:

source /path/to/other/config/file

You can use variables and assign the result of shell commands to them.

set editor=`echo \$EDITOR`

Here the $ gets escaped so that it does not get substituted by Mutt before being passed to the shell. Also note the use of the backquotes, as bash syntax $(...) does not work. Mutt has a lot of predefined variables, but you can also set your own. User variable must begin with "my"!

set my_name = "John Doe"


Native and external setups

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.

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

If unset, the password will be prompted for.

set imap_pass=SECRET

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 do not 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/

It should be noted that for several accounts, it is best practice to use different folders -- e.g. for account-hook. If you have several Gmail account, use

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

instead, where your account is username@gmail.com.


You can now use '=' or '+' as a substitution for the full folder path that was configured above. For example:

set spoolfile=+INBOX

Any imap folders that should be checked regularly for new mail should be listed here:

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

Alternatively, check for all subscribed IMAP folders (as if all were added with a mailboxes line):

set imap_check_subscribed

These two versions are equivalent, but the first is much more convenient. Also, newer Mutt versions are 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.


Using these options, you will be able to start Mutt, enter your IMAP password, and start reading your mail. Here is a muttrc snippet (for Gmail) with some other lines you might consider adding for better IMAP support.

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

# store message headers locally to speed things up
# if hcache is a folder, Mutt will create sub cache folders for each account which may speeds things even more up
set header_cache = ~/.mutt/hcache

# specify where to save and/or look for postponed messages
set postponed = +[Gmail]/Drafts

# allow Mutt to open new imap connection automatically
unset imap_passive

# 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 mail for offline-use. The OfflineIMAP article describes how to download your emails to a local folder which can then be processed by Mutt.

Consider using applications such as spamassassin or imapfilter to sort mail.


Retrieving and sorting mail with external applications

Retrieving mail

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

Here is an example getmailrc used with a gmail account.

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

type = Maildir
path = ~/mail/

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

Most people will like to add the following section to their getmailrc to prevent all the mail on the server being downloaded every time getmail is ran.

read_all = False

As you can see ~/.getmail/getmailrc contains sensitive information (namely, email account passwords in plain text). You will want to change access permissions to the directory so only the owner can see it:

$ chmod 700 ~/.getmail

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:

 */10 * * * * /usr/bin/getmail

That will run getmail every 10 minutes.

Also, to quiet getmail down, we can reduce its verbosity to zero by adding the following to getmailrc.

verbose = 0
More than one Email account with getmail

By default, when you run getmail the program searches for the file getmailrc created as seen above. If you have more than one mail account you would like to get mail from, then you can create such a file for each email address, and then tell getmail to run using both of them. Obviously if you have two accounts and two files you cannot have both of them called getmailrc. What you do is give them two different names, using myself as an example: I call one personal, and one university. These two files contain content relevant to my personal mail, and my university work mail respectively. Then to get getmail to work on these two files, instead of searching for getmailrc(default), I use the --rcfile switch like so: getmail --rcfile university --rcfile personal This can work with more files if you have more email accounts, just make sure each file is in the .getmail directory and make sure to alter the cronjob to run the command with the --rcfile switches. E.g.

 */30 * * * * /usr/bin/getmail --rcfile university --rcfile personal

Obviously you can call your files whatever you want, providing you include them in the cronjob or shell command, and they are in the .getmail/ directory, getmail will fetch mail from those two accounts.

Sorting mail

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

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

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.


* ^To: happy-kangaroos@nicehost.com

* ^From: loveydovey@iheartyou.net

After you have 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 will not give meaningless error message if you do not.


Maildir is a generic and standardized format. Almost every MUA is able to handle Maildirs and Mutt's support is excellent. There are just a few simple things that you need to do to get Mutt to use them. Open your muttrc and add the following lines:

set mbox_type=Maildir
set folder=$HOME/mail
set spoolfile=+/
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 not 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.


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

set smtp_url=smtps://$my_user:$my_pass@smtp.domain.tld
set ssl_force_tls = yes

Note that if your SMTP credentials are the same as your IMAP credentials, than you can use those variables:

set smtp_url=smtps://$imap_user:$imap_pass@smtp.domain.tld

You may need to tweak the security parameters. If you get an error like SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol, then your server most probably uses the SMTP instead of SMTPS.

set smtp_url=smtp://$imap_user:$imap_pass@smtp.domain.tld

There is other variable that you may need to set. For example for use of STARTTLS:

set ssl_starttls = yes

External SMTP support

An external SMTP agent such as msmtp or SSMTP can also be used. This section exclusively covers configuring Mutt for msmtp.

Edit Mutt's configuration file or create it if unpresent:

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

Sending mails from Mutt

Now, startup mutt:

You should see all the mail in ~/mail/inbox. Press Template:Keypress to compose mail; it will use the editor defined by your EDITOR environment variable. If this variable is not set, you can fix it before starting Mutt:

$ export EDITOR=your-favorite-editor
$ mutt

You should store the EDITOR value into your shell resource configuration file (such as bashrc). You can also set the editor from Mutt's configuration file:

set editor=your-favorite-editor

For testing purposes, address the letter to yourself. After you have written the letter, save and exit the editor. You will return to Mutt, which will now show information about your e-mail. Press Template:Keypress to send it.

Multiple accounts

Now you should have a working configuration for one account at least. You might wonder how to use several accounts, since we put everything into a single file. Mutt can handle this thanks to one of its most powerful feature: hooks. Basically a hook is a command that gets executed before a specific action. There are several hook availables. For multiple accounts, either account-hooks or folder-hooks are useful. Folder-hooks will run a command before switching folders. Let's give an example with folder-hooks:

folder-hook 'personal' 'source ~/.mutt/personal_config'
folder-hook 'work' 'source ~/.mutt/work_config'

## Switch to default account on startup.
source "~/.mutt/work_config"

In that case, all the IMAP/POP3/SMTP config for each account should go to its respective folder.

Warning: When one account is setting a variable that is not specified for other accounts, you must unset it for them, otherwise configuration will overlap and you will most certainly experience unexpected behaviour.

Now all your accounts are set, start Mutt. To switch from one account to another, just change the folder (Template:Keypress key). But since you have to type the complete address -- for IMAP/POP3 folders, this may be quite inconvenient -- let's bind some key to it.

## Shortcuts
macro index <f2> '<sync-mailbox><enter-command>source ~/.mutt/personal_config<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.mutt/work_config<enter><change-folder>!<enter>'

Passwords management

Keep in mind that writing your password in .muttrc is a security risk, and it might be of your concern. The trivial way to keep your passwords safe is not writing them in the config file. Mutt will then prompt for it when needed. However, this is quiet combersome in the long run, especiallly if you have several accounts.

Here follows a smart and convenient solution: all your passwords are encrypted into one file and Mutt will prompt for a passphrase on startup only. Since GPG is a Mutt dependency, we will use it, but you can use any other keyring tool as well (e.g. pwsafe).

First create a pair of public/private keys:

gpg --gen-key
Note: Do not leave any blank when giving your full name (surname and given name). Use Template:Keypress or Template:Keypress as a separator

If you do not understand this process have a look at Wikipedia/Asymmetric cryptography.

Create a file in a secure environment since it will contain your passwords for a couple of seconds:

set my_pw_personal = ****
set my_pw_work = ****

Now encrypt the file:

gpg -e -r <your-name> ~/.my-pwds

Note that <your-name> must match the one you provided at the gpg --gen-key step. Now you can wipe your file containing your passwords in clear:

wipe -l2 -x7 -p3 ~/.my-pwds
Note: you must first install wipe if not already installed

Back to your account dedicated files, e.g. .mutt/personal_config:

set imap_pass=$my_pw_personal
# Every time the password is needed, use $my_pw_personal variable.

And in your .muttrc, before you source any account dedicated file:

source "gpg2 -dq ~/.my-pwds.gpg |"
  • The -q parameter makes gpg2 quiet which prevents gpg2 output messing with Mutt interface.
  • The pipe | at the end of a string is the Mutt syntax to tell that you want the result of what is preceeding.

Explanation: when Mutt starts, it will first source the result of the password decryption, that's why it will prompt for a passphrase. Then all passwords will be stored in memory in specific variables for the time Mutt runs. Then when a folder-hook is called, is sets the imap_pass variable to the variable holding the appropriate password. When switching account, the imap_pass variable will be set to another variable holding another password, etc.

If you use external tools like OfflineIMAP and msmtp, you need to set up an agent (e.g. gpg-agent, see GnuPG#gpg-agent) to keep the passphrase into cache and thus avoiding those tools always prompting for it.


Guides to get you started with using & customizing Mutt :

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


You can install muttprintAUR from the AUR for a fancier printing quality. In your muttrc file, insert:

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

Custom mail headers

One of the greatest thing in Mutt is that you can have full control over your mail header.

First, make your headers editable when you write e-mails:

set edit_headers=yes

Mutt also features a special function my_hdr for customizing your header. Yes, it is named just like a variable, but in fact it is a function.

You can clear it completely, which you should do when switching accounts with different headers, otherwise they will overlap:

unmy_hdr *

Other variables have also an impact on the headers, so it is wise to clear them before using my_hdr:

unset use_from
unset use_domain
unset user_agent

Now, you can add any field you want -- even non-standard one -- to your header using the following syntax:

my_hdr <FIELD>: <VALUE>

Note that <VALUE> can be the result of a command.


## Extra info.
my_hdr X-Info: Keep It Simple, Stupid.

## OS Info.
my_hdr X-Operating-System: `uname -s`, kernel `uname -r`

## This header only appears to MS Outlook users
my_hdr X-Message-Flag: WARNING!! Outlook sucks

## Custom Mail-User-Agent ID.
my_hdr User-Agent: Every email client sucks, this one just sucks less.

Signature block

Create a .signature in your home directory. Your signature will be appended at the end of your email. Alternatively you can specify a file in your Mutt configuration:

set signature="path/to/sig/file"

Random signature

You can use fortune to add a random signature to Mutt.

$ pacman -S fortune-mod

Create a fortune file and then add the following line to your .muttrc:

set signature="fortune pathtofortunefile|"

Note the pipe at the end. It tells Mutt that the specified string is not a file, but a command.

Viewing URLs & opening your favorite web browser

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 urlviewAUR from the AUR.

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

REGEXP (((http|https|ftp|gopher)|mailto)[.:][^ >"\t]*|www\.[-a-z0-9.]+)[^ .,;\t>">\):]
COMMAND <your-browser> %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. Your browser will start and go to the selected site.

Some browser will require additional arguments to work properly. For example, Luakit will close on Mutt exit. You need to fork it to background, using the -n parameter:

COMMAND luakit -n %s 2>/dev/null

The 2>/dev/null is to make it quiet, i.e. to prevent useless message printing where you do not want them to.

  • Note - If you have some problems with urlview due to Mutt's url encoding you can try extract_url.pl
  • Note - If you would like to see a short contextual preview of the content around each URL, try urlscan. The macro in your muttrc is the same as for urlview (except for the 'urlscan' command). There is no additional configuration required other than ensuring $BROWSER is set.

Viewing HTML

It is possible to pass the html body to an external HTML program and then dump it, keeping email viewing uniform and unobtrusive. Two programs are described here: lynx and w3m.

Install lynx or w3m:

pacman -S lynx


pacman -S w3m

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

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

or, in case of w3m,

text/html; w3m -I %{charset} -T text/html; copiousoutput;

Edit muttrc and add the following,

set mailcap_path 	= ~/.mutt/mailcap

To automatically open HTML messages in lynx, add this additional line to the muttrc:

auto_view text/html

The beauty of this is, instead of seeing an html body as source or being opened by a separate program, in this case lynx, you see the formatted content directly, and any url links within the email can be displayed with Template:Keypress.

If you receive many emails with multiple or alternate encodings Mutt may default to treating every email as html. To avoid this, add the following variable to your ~/.muttrc to have Mutt default to text when available and use w3m/lynx only when no text version is availble in the email:

alternative_order text/plain text/html

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
  • Another choice is to use Vim's mail filetype plugin to enable other mail-centric options besides 72 character width. Edit ~/.vim/filetype.vim, creating it if unpresent, and add:
augroup filetypedetect
  " Mail
  autocmd BufRead,BufNewFile *mutt-*              setfiletype mail
augroup END
  • To set a different tmp 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

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"

Mutt and Emacs

Emacs has a mail major mode. To switch to mail-mode automatically when Emacs is called from Mutt, you can add the following to your .emacs:

;; Mutt support.                                                                                                                                                          
(setq auto-mode-alist
       '(("/tmp/mutt.*" . mail-mode)

If you usually run Emacs daemon, you may want Mutt to connect to it. Add this to your .muttrc:

set editor="emacsclient -a \"\" -t"


Append sample color definitions to your .muttrc file:

$ cat /usr/share/doc/mutt/samples/colors.linux >> ~/.muttrc

Then adjust to your liking. The actual color each of these settings will produce depends on the colors set in your ~/.Xresources file.

Alternatively, you can source any file you want containing colors (and thus act as a theme file):

source ~/.mutt/colors.zenburn

A nice theme example:

## Theme kindly inspired from                                                                                                                                             
## http://nongeekshandbook.blogspot.ie/2009/03/mutt-color-configuration.html                                                                                              

## Colours for items in the index                                                                                                                                         
color index brightcyan black ~N
color index brightred black ~O
color index brightyellow black ~F
color index black green ~T
color index brightred black ~D
mono index bold ~N
mono index bold ~F
mono index bold ~T
mono index bold ~D

## Highlights inside the body of a message.                                                                                                                               

## URLs                                                                                                                                                                    
color body brightgreen black "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
color body brightgreen black "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"
mono body bold "(http|ftp|news|telnet|finger)://[^ \"\t\r\n]*"
mono body bold "mailto:[-a-z_0-9.]+@[-a-z_0-9.]+"

## Email addresses.                                                                                                                                                       
color body brightgreen black "[-a-z_0-9.%$]+@[-a-z_0-9.]+\\.[-a-z][-a-z]+"

## Header                                                                                                                                                                 
color header green black "^from:"
color header green black "^to:"
color header green black "^cc:"
color header green black "^date:"
color header yellow black "^newsgroups:"
color header yellow black "^reply-to:"
color header brightcyan black "^subject:"
color header red black "^x-spam-rule:"
color header green black "^x-mailer:"
color header yellow black "^message-id:"
color header yellow black "^Organization:"
color header yellow black "^Organisation:"
color header yellow black "^User-Agent:"
color header yellow black "^message-id: .*pine"
color header yellow black "^X-Fnord:"
color header yellow black "^X-WebTV-Stationery:"

color header red black "^x-spam-rule:"
color header green black "^x-mailer:"
color header yellow black "^message-id:"
color header yellow black "^Organization:"
color header yellow black "^Organisation:"
color header yellow black "^User-Agent:"
color header yellow black "^message-id: .*pine"
color header yellow black "^X-Fnord:"
color header yellow black "^X-WebTV-Stationery:"
color header yellow black "^X-Message-Flag:"
color header yellow black "^X-Spam-Status:"
color header yellow black "^X-SpamProbe:"
color header red black "^X-SpamProbe: SPAM"

## Coloring quoted text - coloring the first 7 levels:                                                                                                                    
color quoted cyan black
color quoted1 yellow black
color quoted2 red black
color quoted3 green black
color quoted4 cyan black
color quoted5 yellow black
color quoted6 red black
color quoted7 green black

## Default color definitions                                                                                                                                              
#color hdrdefault white green                                                                                                                                             
color signature brightmagenta black
color indicator black cyan
color attachment black green
color error red black
color message white black
color search brightwhite magenta
color status brightyellow blue
color tree brightblue black
color normal white black
color tilde green black
color bold brightyellow black
#color underline magenta black                                                                                                                                            
color markers brightcyan black

## Colour definitions when on a mono screen                                                                                                                               
mono bold bold
mono underline underline
mono indicator reverse

Index Format

Here follows a quick example to put in your .muttrc to customize the Index Format, i.e. the columns displayed in the folder view.

set date_format="%y-%m-%d %T"
set index_format="%2C | %Z [%d] %-30.30F (%-4.4c) %s"

See the Mutt Reference, man 3 strftime and man 3 printf for more details.

Address aliases

Aliases is the way Mutt manages contacts. An alias is nickname [longname] <address>.

  • The nickname is what you will type in Mutt to get your contact address. One word only, and should be easy to remember.
  • The longname is optional. It may be several words.
  • An <address> must be in a valid form (i.e. with an Template:Keypress).

It is quite simple indeed. Add this to .muttrc:

set alias_file = "~/.mutt/aliases"
set sort_alias = alias
set reverse_alias = yes
source $alias_file


  • alias_file is the file where the information is getting stored when you add an alias from within Mutt.
  • sort_alias specifies which field to use to sort the alias list when displayed in Mutt. Possible values: alias, address.
  • reverse_alias sorts in reverse order if set to yes.
  • source $alias_file tells Mutt to read aliases on startup. Needed for auto-completion.

Now all you have to do when prompted To: is writing the alias instead of the full address. The beauty of it is that you can auto-complete the alias using Template:Keypress. Autocompleting a wrong or an empty string will display the full list. You can select the alias as usual, or by typing its index number.

There is two ways to create aliases:

  • From Mutt, press Template:Keypress when an e-mail of the targetted person if selected.
  • Edit the alias_file manually. The syntax is really simple:
alias nickname Long Name <my-friend@domain.tld>

Tips and tricks

Request IMAP mail retrieval manually

If you do not want to wait for the next automatic IMAP fetching (or if you did not enable it), you might want to fetch mails manually. There is a mutt command imap-fetch-mail for that. Alternatively, you could bind it to a key:

bind index "^" imap-fetch-mail

Speed up folders switch

Add this to your .muttrc:

set sleep_time = 0

Use Mutt to send mail from command line

Man pages will show all available commands and how to use them, but here are a couple of examples. You could use Mutt to send alerts, logs or some other system information, triggered by login through .bash_profile, or as a regular cron job.

Send a message:

mutt -s "Subject" somejoeorjane@someserver.com < /var/log/somelog

Send a message with attachment:

mutt -s "Subject" somejoeorjane@someserver.com -a somefile < /tmp/sometext.txt

Composing HTML e-mails

Since Mutt has nothing of a WYSIWIG client, HTML is quite straightforward, and you can do much more than with all WYSIWIG mail clients around since you edit the source code directly. Simply write your mail using HTML syntax. For example:

This is normal text<br>
<b>This is bold text</b>

Now before sending the mail, use the edit-type command (default shortcut Template:Keypress), and replace text/plain by text/html.

Note: HTML e-mails are regarded by many people as useless, cumbersome, and subject to reading issues. Mutt can read HTLM mails with a text browser like w3m or lynx, but it has clearly no advantage over a plain-text e-mail. You should avoid writing HTLM e-mails when possible.

How to display another email while composing

A common complaint with Mutt is that when composing a new mail (or reply), you cannot open another mail (i.e. for checking with another correspondent) without closing the current mail (postponing). The following describes a solution:

First, fire up Mutt as usual. Then, launch another terminal window. Now start a new Mutt with

mutt -R

This starts Mutt in read-only mode, and you can browse other emails at your convenience. It is strongly recommended to always launch a second Mutt in read-only mode, as conflicts will easily arise otherwise.

Now, this solution calls for a bit of typing, so we would like to automate this. The following works with Awesome, in other WM's or DE's similar solutions are probably available: just google how to add a key binding, and make the desired key execute

$TERM -e mutt -R 

where $TERM is your terminal.

As for Awesome: edit your rc.lua, and add the following on one of the first lines, after terminal = "yourTerminal" etc.

mailview = terminal .. " -e mutt -R"

This automatically uses your preferred terminal, ".." is concatenation in Lua. Note the space before -e.

Then add the following inside --{{{ Key bindings

awful.key({ modkey,           }, "m", function() awful.util.spawn(mailview) end),

Omit the final comma if this is the last line. You can, of course use another key than "m". Now, save&quit, and check your syntax with

awesome -k

If this is good, restart awesome and give it a try!

Now, a usage example: Launch Mutt as usual. Start a new mail, and then press "Mod4"+"m". This opens your mailbox in a new terminal, and you can browse around and read other emails. Now, a neat bonus: exit this read-only-Mutt with "q", and the terminal window it created disappears!


mutt-sidebarAUR - A patch for a list of folders on the left side of the Mutt window.

mutt-sidebar maintainer website and documentation

Migrating mails from one computer to another

In case you are transfering your mails to a new machine (copy&paste), you probably need to delete ~/.hcache to make mutt able to read your migrated E-Mails. Otherwise mutt may freeze.


Backspace does not work in Mutt

This is a common problem with some xterm-like terminals. Two solutions:

  • Either rebind the key in .muttrc
bind index,pager ^? previous-page

Note that ^? is one single character representing backspace in Caret notation. To type in Emcas, use Template:Keypress, in Vim Template:Keypress.

  • Or fix your terminal:
$ infocmp > termbs.src                                                                                                                                                   

Edit termbs.src and change kbs=^H to kbs=\177, then:

$ tic -x termbs.src

See also