A Quick Guide To Mutt v1.5.17
A Quick Guide To Mutt v1.5.17
A Quick Guide To Mutt v1.5.17
mutt
Main page
Basics
I'm going to assume you already have mutt installed. I think that almost every distribution has a
package for it. If not, you can get the tarball from mutt's site. That link goes to the development
directory. There have been some changes between mutt-1.4.x and 1.5.x, and this article covers 1.5.x.
I would suggest getting the latest development version, 1.5.17, at time of writing. It's configured in
the usual way. Download the tarball, uncompress and untar it and do configure, make and make
install. If you had downloaded mutt-1.5.17.tar.gz
tar zxvf mutt-1.5.17.tar.gz
We're going to assume that your main email account is john@example.com. Your password on that
account is 1234. Your POP server is pop.example.com and your smtp server is smtp.example.com.
Your account on the box is john. The first step is to set up getmail. (Note that while this next section
seems a bit involved, it's actually quite easy.)
(If you want to use fetchmail, I have a quick and dirty guide to it which can be viewed here.
However, that page hasn't been updated in years. If the reader feels they'd rather use fetchmail, then
they'd be better off finding a different tutorial.
(Back to Contents)
1/24
5/31/2015
mutt
(The unixfrom line is necessary for both procmail and maildrop, which we'll be using later. I don't
know about other MDA's.).
The above will work for mbox format. If you have maildir format, then you would change the type
from Mboxrd to Maildir and the path to ~/Maildir/IN-personal. You might have to do ~/Maildir/INpersonal/ with the trailing slash, I haven't worked with maildir format for awhile.
Note that the path has to exist--getmail won't create it for you. As mentioned in the next section,
mutt will, depending upon the system's defaults, offer to create your Mail or Maildir directory. You
can then create a mailbox (or subdirectory in Maildir format) called IN-personal. (You can call it
whatever you wish of course, IN-personal is an example.)
If you start filtering email you will change the destination parameter from a mailbox or mail
directory to an external program. Using maildrop on a Linux box, where maildrop's path is
/usr/bin/maildrop, I have
[destination]
type = MDA_external
path = /usr/bin/maildrop
unixfrom = True
As gmail becomes more and more popular, folks are often making use of its pop download feature,
enabling you to receive your gmail email on your normal client (in this case, of course, mutt.) As
gmail uses SSL the above configuration would work save for the SimplePop3Retriever line. For a
gmail account, you want, assuming your gmail account is john@gmail.com with a password of 1234
[options]
verbose = 0
delete = True
[retriever]
type = SimplePOP3SSLRetriever
server = pop.gmail.com
username = john@gmail.com
password = 1234
[destination]
type = Mboxrd
path = ~/IN-personal
unixfrom = True
Save that one as a second file in your .getmail directory, e.g., gmailrc. (Each account requires a
separate rc file.)
If you're on a box that others use, this means that your email password is visible to the super user.
So, you can leave out the password line. However, this will mean that you have to enter it in each
time getmail polls your server.
In general, I like to have getmail running in the background, checking for mail every ten minutes.
With fetchmail, one does this with the -d option, making it run as daemon. However, getmail doesn't
have this option--while some people write a script to do it, I follow the getmail author's advice, and
run it as cronjob. For the newcomer unfamiliar with cron, it's used to run a job at regular intervals.
There are six fields, minutes, hour, day of month, month, day of week and the actual job itself. In
this case, I want getmail to run every ten minutes, regardless of the hour, day, etc. Therefore, the
only fields specified are minutes and the actual job. This isn't a page about cron, so I'll simply give
the procedure to have getmail poll the pop server every ten minutes.
http://srobb.net/mutt.html
2/24
5/31/2015
mutt
Again, we'll have a user named john. We'll assume that you're new to this (otherwise, you probably
wouldn't be reading this section) and haven't given john a crontab or any specific jobs.
crontab -e
The e means you're going to edit the crontab. You'll probably get an empty editor. In my case, vi is
my default editor, so vi opens. For getmail to check for mail every 10 minutes, I would put
*/10 * * * * /usr/local/bin/getmail
The numbers refer to minutes, the 4 *'s refer to the fields I'm not specifying, hours, day of month,
etc and the last field is the command.
If you wanted to stop the cronjob for some reason--for example, if you were going to work and get
mail there during the day, you just do crontab -e again and comment out the line by putting a # in
front of it. Then it would look like
#*/10 * * * * /usr/local/bin/getmail
One quick note of warning. If you wanted the job to run every two hours and made a crontab like
this
* */2 * * *
it would be running every minute. The correct way to specify the job to run every two hours would
be
0 */2 * * *
If you have more than one getmailrc file--as in our example above, when you have your
example.com account and gmail account, they both have to be specified in your cronjob. -r is used
as short for -rcfile, and you don't need a space after the -r.
*/10 * * * * /usr/local/bin/getmail -rgetmailrc -rgmailrc
If you've set up getmail this way, as a cron job, you can either leave mutt open all the time and
check your various mailboxes periodically, or, at least in X, use xbuffy to keep track of your emails.
If just watching one mailbox, xbiff, part of xorg-x11-apps, at least in RH based systems, will work.
You can set its geometry, color, and so on, either at the command line or by putting entries in your
$HOME/.Xdefaults. By default, its size is 48x48 and it watches your default mail, usually
/var/spool/mail or something similar. If you make an .Xdefaults entry of
xbiff*file:/home/john/Mail/IN-personal
to just set the size. To set it to always show up in the bottom right of your window you can use -0-0,
with no spaces, in other words
xbiff*geometry:48x25-0-0
To set a corner in .Xdefaults, one uses +0+0 for upper left, -0+0 for upper right, -0-0 for lower right
and +0-0 for lower left. To get other locations, you have to play around--for example, on a screen
with a resolution of 1920x1080, to get it approximately in the upper middle, I would use
48x25+960+0 and +960-0 to get it on the bottom. To start with +0 puts it at the far left and -0 at the
far right. The second number is top or bottom, +0 being the top and -0 being the bottom. (Note that
with dwm the top will be below the dwm status bar.) There's a nice page at umd.edu that explains
the X Y coordinates in more detail.
(Back to Contents)
3/24
5/31/2015
mutt
Many thanks to several members of bsdnexus.com's forums who were kind enough to take the
trouble to tell me where their various O/S's put the system wide Muttrc.)
A common problem for those using Maildir format is that when they open mutt they'll get a message
like
/home/john/Maildir is not a mailbox
The Maildir format requires 3 subdirectories in there, cur new and tmp. With the maildrop program
there's a maildirmake command which will properly create the directory.
maildirmake ~/Maildir
If you've already made your Maildir without the subdirectories you can make them yourself.
cd ~/Maildir
mkdir -m 700 cur new tmp
While on Maildir format, although the mbox format will show the size of each mailbox, letting you
know approximately how much new mail you have, Maildir will just show everything as having a
size of 512.
However, if you have a mail directory in your Maildir folder, called, for example, IN-personal, you
can add the following to your .muttrc
mailboxes ~/Maildir/IN-personal
Then, when you receive new mail an N will appear in front of any mailboxes specified in .muttrc
that have new mail.
I haven't looked deeply into this. Sometimes, it doesn't seem to work the way I expected, but these
days, as I use mbox format, I never researched it.
When using Maildir format, I've found that you have to create all directories before applying
filtering rules. That is, if I have a maildrop or procmail rule to send mail to IN-personal, I have to
create the Maildir/IN-personal directory first. This can be done with maildirmake as mentioned
above. Again, we'll be dealing with filtering later in this article. Additionally, even a getmailrc that
delivers directly to your Maildir directory needs to have the mailboxs created in advance. Again,
we'll be dealing with filtering later in this article. Additionally, remember that even a getmailrc that
delivers directly to your Maildir directory needs to have the mailboxes created in advance
cd ~/Maildir
maildirmake IN-personal
Otherwise, the directory and subdirectories can once again be created manually.
cd ~/Maildir
mkdir -m 700 IN-personal
cd IN-personal
mkdir -m 700 cur new tmp
If you start getmail, and receive some mail, you'll now be able to read messages in mutt.
The menu is at the top of the display. However, you won't be able to send yet.
One thing to note with a .muttrc--if there are two conflicting rules in it, it will almost always process
the last one. However, as noted below, fcc-hooks are an exception. There are other exceptions as
well, such as colors.
(Back to Contents)
IMAP
Before beginning, note that some of the options mentioned here, such as header_cache and
smtp_user, are not necessarily compiled into mutt by default. For example, on a FreeBSD 9.2-RC3
installation, when I added the set imap_user into my .muttrc, when I next started mutt, I got an error
of unknown option. I had to cd into /usr/ports/mail/mutt and reconfigure to add it, by typing make
config. I then had to run make deinstall and make install. The easiest way to tell if it's a typo in your
.muttrc is to check the systemwide /etc/Muttrc (or /usr/local/etc/Muttrc in FreeBSD's case) to see if
the option is there. If it's definitely there, and you're getting an unknown option error when starting
mutt, then it indicates that your particular install was compiled without those options. You can
always run
mutt -version
which will show you what options are there and not there. For example, a default CentOS install
shows me
+USE_SMTP
but a default FreeBSD install, unless I've explicitly configured it in the dialog when installing, will,
if I type mutt -version, show -USE_SMTP, indicating that it is not compiled in. Therefore, I had to
run make deinstall, make config to get the option dialog, add the support, and then run make
reinstall, or make install clean.
Generally, I prefer to pull in my mail, using getmail as described above. However, mutt also works
with an IMAP server. If only using one IMAP server with one mailbox, one can add the following to
~/.muttrc. Assuming the user name is john, the password, 1234, and the server name is
imap.example.com
set imap_user="john"
set imap_pass="1234"
http://srobb.net/mutt.html
4/24
5/31/2015
mutt
When sending through most imap servers you need to specifically tell it to keep your sent emails.
Assuming your default sent mailbox on the imap server is Sent, you can add this to your
$HOME/.muttrc.
set record="Sent"
In my particular, possibly unusual case, although I usually pull in mail from my IMAP server, on
occasion, I want to just log into it. Rather than have something set in my .muttrc, I temporarily set
the MAIL environment variable. This is generally set to /var/spool/$USERNAME or
/var/spool/mail/$USERNAME--in other words, with our user of john, it would be set to
/var/spool/mail/john. Resetting it completely might (or might not) affect other things that depend
upon the variable, so I just made a little script, checkimap.sh
#!/bin/sh
MAIL=imap://john@imap.example.com
mutt
Make it executable with chmod 700 checkimap.sh. It will then temporarily change your MAIL
environment variable to the IMAP server and check your inbox there.
As I don't use this much, I haven't investigated doing much more than that, such as handling
multiple imap mailboxes. You might want to add
set folder="imap://john@imap.example.com/"
This should put you in the imap directory, enabling you to see all subfolders. If you just want to be
in the inbox, you could use imap://john@imap.example.com/INBOX, assuming that INBOX is the
directory you want. If you have all your subdirectories under that, it will work. If your various
subdirectories are on the same level as your inbox, then use the first example, that doesn't include
"INBOX" (or whatever you call your inbox). By same level, I mean that if using thunderbird, for
example, you logged into your imap account, and see INBOX, MYGROUPS, SALES and so on,
then all those mailboxes would be on the same level. Other people have one INBOX, and then,
inside the INBOX, make their subdirectories. This mutt wiki page goes over using imap with mutt.
In another situation, I found that the above gave me login errors. The address was
john@example.com but the server name was mail.example.com. When I used
set imap_user="john@example.com
set folder="imap://john@mail.example.com"
Actually, in that case, it was using SSL so I had to change the second line to
imaps://mail.example.com. Regardless, the user was my email address, and the folder, rather than
user@host, was just the host.
Another thing, that didn't happen to me, but has happened, is that for whatever reason, (perhaps
because it was built without SSL or TLS), that mutt won't properly transmit a password from
.muttrc. That is, if you have the suggested.
set imap_pass="1234"
you might get a login failed message. However, if you leave out the set_imap_pass from your
.muttrc file and just type in the password when requested, it works. I haven't run into this, and only
found out about it when researching something else (the problem I mentioned above, when the user
is john@example.com and the server is mail.example.com), but mention it as something for a user
to try if they're unable to log into their imap account.
Using IMAP can be surprisingly slow. One easy way to speed it up is to create a .mutt_cache in your
home directory.
mkdir ~/.mutt_cache
(Note the dot in front of the name, making it a hidden directory). Then, add to your ~/.muttrc
set header_cache="~/.mutt_cache"
Then mutt will cache the IMAP headers in your $HOME/.mutt_cache. This will greatly increase
speed with IMAP directories.
Even if not using IMAP, creating a .mutt_cache directory and adding a line referencing it in your
.muttrc can speed up mutt's handling of large mbox files or maildir directories.
(Back to Contents)
Sending mail
If you're really impatient, and just want to send mail through a basic pop3 account that doesn't
require authorization, you can add the followiong to your .muttrc. Our user John at example.com,
doesn't have to provide a username and password to send, only to receive. So, he could add
set smtp_url="smtp://smtp.example.com"
Now, if you hit y to send your mail, it will use your ISP's server.
If your ISP uses a secure server, then it would read something like
set smtp_url="smtps://john:1234@smtp.example.com:465
http://srobb.net/mutt.html
5/24
5/31/2015
mutt
465 is a commonly used port for smtps. However, always check with your ISP, or read their setup
information for sending mail. Gmail uses authentication and TSL, I believe, and for sending, you
need to use port 587. The last time I looked, their help site said that you could use either one, but
thanks to a post in their forums by K. Frazier, I found that 587 seems to be necessary.
Gmail's smtp_url setting uses smtp, not smtps.
If setting smtp_url to work with gmail, with the username of john@gmail.com and the password of
1234 you would use
set smtp_url="smtp://john@gmail.com@smtp.gmail.com:587"
set smtp_pass="1234"
I haven't used that method with gmail in years, and the last time I tried, I got a message no
authenticators available. Googling found some solutions for Debian and Ubuntu users (install
libsasl2-modules), and in Fedora and CentOS I got it by installing some cyrus-sasl packages. I think
the only one I really needed was cyrus-sasl-plain. The others I had were cyrus-sasl, cyrus-sasl-gssapi
and cyrus-sasl-lib.
In Arch, it worked without specifically installing anything besides mutt. In my individual case, it
was more curiosity, as I have a few different accounts, which leads nicely to my next point.
The smtp_url line is handy if you only have one account, but these days, many people use multiple
accounts. Therefore, I recommend msmtp.
The msmtp program has a very simple syntax and the configurations given in the man page are
straightforward.
Create a $HOME/.msmtprc file, giving it permissions of 0600 (otherwise, you get an error
message.) Again, we'll assume the username of john@example.com with an smtp server of
smtp.example.com The file should read
account examplecom
host smtp.example.com
from john@example.com
account default : examplecom
Those are the four absolutely necessary entries. The line account is your own name for the account.
You can call it what you wish. The host line is the address of your ISP's smtp server. The from line
is the address that appears in the From: part of your email. The account default line is necessary,
even if you only have one account, otherwise msmtp exits with an error.
One then adds the following line to .muttrc
set sendmail="/usr/local/bin/msmtp"
(A reminder that I am using /usr/local/bin because that's where it is with FreeBSD. Your system
may have it in a different place--one can always check with the command
whereis msmtp
For gmail, it's somewhat different. If the user name is john@gmail.com and he has a gmail password
of 1234.
#Gmail
account gmail
host smtp.gmail.com
from john@gmail.com
auth on
tls on
tls_trust_file /etc/ssl/cert.pem
user john@gmail.com
password 1234
port 587
account default : gmail
The man page also gives clear instructions on using msmtp with mutt, including key bindings to
quickly switch between say, a gmail account and another account. The following is more or less a
recap of the man page.
The msmtp man page advises against the tls_certcheck off. Most distributions have a package that
will include it. On Debian (and perhaps Debian based systems) one installs the ca-certificates
package and your tls_trust_file would point to /etc/ssl/certs/ca-certificates.crt. On FreeBSD, it's
included in the /usr/ports/security/ca-root_nss port and the file is in /usr/local/share/certs/ca-rootnss.crt. (FreeBSD installs the ca-root_nss port as a dependency if you install msmtp with openssl or
gnutls support. There is also the option to symlink to /etc/ssl/cert.pem.
With ArchLinux, if you install curl, it can be found in /usr/share/curl/curl-ca-bundle.crt. In Fedora
and CentOS, I found it in /etc/pki/tls/cert.pem. So adjust your .msmtprc tls_trust_file line
accordingly.
In CentOS, I had to compile msmtp from source. It's relatively trivial, but make sure that you have
gnutls and possibly gnutls-devel installed, otherwise, you won't be able to use tls check. For the
beginner, unfamiliar with compiling from source, note that with RedHat based distributions, the
necessary tools aren't installed by default. So, first make sure you have them.
yum install gcc gcc-c++ make automake kernel-devel
This will pull in several other things, such as kernel-headers, as dependencies. Once this is done,
download the tarball from msmtp's site. Get the bz2 file, untar and decompress it, then run configure
and make. For example
tar jxvf msmtp-<version>.tar.bz2
cd msmtp-<version>
./configure
make
http://srobb.net/mutt.html
6/24
5/31/2015
mutt
make install
After running configure, it will show you the options that it has chosen. Make sure, especially if
you're planning to use it with gmail, that it has either tls or SSL. (Again in CentOS and Fedora, you
might have to install gnutls and gnutls-devel with yum install gnutls-devel which will pull in gnutls
as a dependency.)
As mentioned, msmtp works with multiple accounts. Suppose our user john has the gmail account,
john@gmail.com and his account at example.com. He wishes to use both of them, and be able to
switch between them at will. The isp account is john@example.com and also has a password of
1234. Unlike gmail, it doesn't require authentication. He wants the normal account to be his default.
He then edits his .msmtprc to read
#Gmail
account gmail
host smtp.gmail.com
from john@gmail.com
auth on
tls on
tls_trust_file /etc/ssl/cert.pem
user john@gmail.com
password 1234
port 587
account examplecom
host smtp.example.com
from john@example.com
account default : examplecom
Now, if he wishes to send an email from from gmail, first he hits the escape key and the 1 key. (In
this case, this is the numeral one, not a lower case L). If he then hits m to compose mail, it will be
sent from the gmail account. If he then wishes to send another email from his isp.com account, he
hits the escape key and 2 before hitting m to compose his mail, and the new email will come from
john@isp.com
The easiest way to do this is to use the send2-hook. This was lifted almost verbatim from the msmtp
section of the the mutt wiki
send2-hook '~f john@gmail.com' 'set sendmail="/usr/local/bin/msmtp -a gmail"'
send2-hook '~f john@example.com' 'set sendmail="/usr/local/bin/msmtp "'
He doesn't need the -a for account for his examplecom account, because it's defined as his default in
his .msmtprc.
The man page goes into more detail.
With FreeBSD, to get it working properly with gmail, during installation, I had to specify openssl as
an option.
cd /usr/ports/mail/msmtp
make -DWITH_OPENSSL install clean
Note that if you later use portupgrade to upgrade msmtp, you would have to use that with the -m
flag, e.g.
portupgrade -m -DWITH_OPENSSL msmtp
There is another even smaller and simpler utility called nbsmtp, which I cover briefly on another
page. I'm not sure that it's still around. I also have a page on ssmtp, but ssmtp has been abandoned
by its maintainers, so I no longer use it.
(Back to Contents)
Mail headers
Depending upon your computer's systemwide muttrc, mutt might give complete headers for every
email. For the average user, unless trying to track a spammer or troubleshoot a mail server's
configuration, this can be too much information. Therefore, if one only wants to know the standard
info, this hack to the .muttrc file will work. Add the lines
ignore *
unignore date from to cc subject resent-from reply-to x-mailer
(You can change these according to personal taste) The above will just show the from, to, etc rather
than the path, etc.
(Back to Contents)
In /etc/mailcap or your home directory .mailcap, add the following. (In the example, we'll use
http://srobb.net/mutt.html
7/24
5/31/2015
mutt
This should, in most cases, enable you to open the document in line. If you leave the auto_view line
out of your .muttrc, the mailcap entry should still enable you to hit v as in view on the attachment,
and see it as a text document.
One can do the same with Excel sheets and the xls2csv program. Some systems create default
mailcaps, assuming that you're using X, that is, running mutt in an xterminal. They might have
application/msword; ooffice %s
If that is how you plan to use it, in X, then you probably want to remove the autoview line from
your .muttrc. Then, when you receive a .doc attachment, use v to view the attachment, hit enter, and
it will open in OpenOffice. I prefer using catdoc as it enables me to view documents without having
to run an X session.
If using X and running mutt in terminal, the same method can be used to easily view images and
pdfs. Add the following to your $HOME/.mailcap. In this case, we'll assume you use xpdf to view
pdf files and feh to view images. You can change these to your preferred applications. For example,
Gnome users might want to use eog, Eye of Gnome, for images.
image/*; feh %s
application/pdf; xpdf %s
Now, if you receive an attached image or pdf and are in X, you can hit v for view and when the file
is selected, just hit enter. The feh program will open and display the image.
If you're in console, however, rather than xterm, you can view it later while in X, or hit s for save. It
will save the file, by default, to your home directory, and you can then, when in X, view it with your
image viewer of choice. One can also, if using framebuffer in terminal, use fbi to view the image,
but I haven't done this very much. I think the trick would be to change ~/.mailcap to use fbi for
image/* files.
(Back to Contents)
Fedora figures its users will be in X. This can make it difficult to use w3m if in console or connected
via ssh. They have an /etc/mailcap file that seemed to override $HOME/.mailcap. I am not sure if I'd
made typos in my $HOME/.mailcap, or if /etc/mailcap simply took precedence (which it shouldn't-so it's far more likely I had typos in my home .mailcap file.) Anyway, $HOME/.mailcap should have
text/html; w3m -T text/html -dump %s; copiousoutput
Often, if all else fails, (or even if it doesn't), much of the time, html mail will have a text attachment.
If you hit v as in view, when looking at an html mail, you might see a text/html and a text/plain.
Mac's Mail.app, among others, seems to do it this way. You can always just arrow down to the
text/plain and see if it's readable that way.
To follow url's in an email, I use urlview. I've only done it in FreeBSD and Fedora, but hopefully the
reader will be able to modify it for his system. FreeBSD has it in /usr/ports/textproc and I believe
Fedora installs it as a dependency of mutt.
Add the following to your .muttrc
macro pager \cb |urlview\n
macro index \cb |urlview\n
http://srobb.net/mutt.html
8/24
5/31/2015
mutt
Now if I hit ctrl b I simply see a list of urls. I can navigate to the link I wish to follow (with arrow
keys or vi commands) and hit enter. The url is shown at the bottom of the screen, hit enter again, and
the link opens up.
In FreeBSD, there is, when urlview is installed, a script called /usr/local/bin/url_handler.sh that
comes with it. By default, it will open up lynx in console and netscape in X. You will see the line
http_prgs="/usr/local/bin/netscape:XW /usr/local/bin/lynx:XT /usr/local/bin/w3m:XT
/usr/local/bin/links:XT"
I change this to suit my needs--in FreeBSD I change it to
http_prgs="/usr/local/bin/opera:XW /usr/local/bin/w3m:XT"
You'll also see the line
XTERM=/usr/X11R6/bin/xterm
If you prefer another terminal change it. (Of course, if you're in X, the chances are that you use
firefox, opera or the like, so that's probably irrelevant.)
If I am in X, it will open up opera. The above was written some time ago, and firefox might be the
current default. It is in Fedora.
Fedora makes it a bit harder to customize. One can change firefox to opera in /usr/bin/url_handler.sh
and it will be ignored. The trick turns out to be that one must first create a file in their home
directory, .urlview. This should read
COMMAND url_handler.sh %s
Otherwise, it tries to override. I found that I also had to remove htmlview, I am not quite sure why.
If one removes htmlview it will also remove system-config-network, a text interface tool to
configure, oddly enough, the network. One can remove it, however, with
rpm -e --nodeps htmlview
Renaming /usr/bin/htmlview to something like /usr/bin/htmlview.old has the same effect, it removes
it from the equation.
Lastly, one may also have to change default programs in /usr/bin/xdg-open.
Sometimes, as mentioned in this blog post (where I got most of the following), some emails have
the links hidden in HTML, and it becomes necessary to open a browser to actually view an email.
The blogger uses vimprobable, but any browser will do. (I've had trouble building vimprobable or
surf, another lightweight browser, on CentOS 6.x for example, so one can use firefox, or dillo which
is available on CentOS.) Whether or not you have autoview set, in mailcap, above the w3m lines
we've mentioned, one can add
text/html; firefox -new-tab %s; test=test -n "$DISPLAY"
The blog post mentions keybindings, but as I find I only have to use this on very rare occasions, if I
get such an email, I first hit v for view, and then m which will send it to mailcap. This opens up a
browser and shows me the mail. (I should add that one should take care with this, as there can be
security issues with automatically displaying images, but in my case, the emails I've had to do this
with were from known sources.
Dillo may not display the images. In my own case, I seldom want them anyway, I would just want
the necessary links.
Sometimes, hitting v will just show one line, something like no description text/html. Othertimes,
there may be a few lines, such multipart/alternative, text/plain and text/html. In such cases, if you hit
m while highlighting multipart or text plain, you may get an error. You have to navigate down, with
arrow key or (in vi at least) j to get to the text/html line.
One last, somewhat related topic. If you wish to use mutt with a graphic browser, it's not difficult. In
opera one just goes to Tools => Preferences =>Programs and paths =>E-mail. The default is to use
opera's email, but below that you are given the option to open it with another application. I use the
following--this will give me a To: as specified in the mailto and also a subject if the subject is coded
in the mailto link. I use mlterm as my terminal. You can substitute this with the xterm of your
choice.
mlterm -e mutt [-s %s] "%t"
Quote only the %t as shown in the example. That represents the To: line. The %s for the subject has
to be in brackets, or it will be passed as one argument--in other words, if the code on the web page
was something like mailto:john@example.com?subject=hello, if the %s is not in brackets and you
click the link it will come out as something like To:john@example.comhello.
With opera 9.50 beta, on Fedora, it was slightly different. I had to use mutt as the program name.
Then, I put the [-s %s] "%t" part in the textbox marked Parameter. Lastly, I checked the box that
says Open in terminal.
For Mozilla and firefox, it's a bit more complex. My friend Godwin has a page about it that explains
the various steps quite well. I will give a very quick recap here. Go to about:config (if you're not
familiar with firefox, just type
about:config
http://srobb.net/mutt.html
9/24
5/31/2015
mutt
It is probably set to true by default--if not, right click and choose the toggle option. Then, right click
any setting, choose New and String. For the string put
network.protocol-handler.app.mailto
Create a script called mailto.sh and put it in /usr/local/bin/ or $HOME/bin or wherever you put your
custom scripts, as long as it's in your $PATH. In this example, I am using mlterm, my usual
terminal, but use xterm, kterm or whatever you usually prefer
#!/bin/sh
mlterm -e mutt "$1"
For more details, including screenshots, see Godwin's page. (Although he doesn't cover mutt)
One can edit their prefs.js file instead. This is found in $HOME/.mozilla/firefox/something.default
directory--the something being a random string of letters and/or numbers. If one chooses this
method, the two lines would read
user_pref("network.protocol-handler.app.mailto", "mailto.sh");
user_pref("network.protocol-handler.external.mailto", true);
Macros
Macros are handy, but the average user finds the mutt handbook's explanation somewhat terse.
FreeBSD has some sample macros in /usr/local/share/examples/mutt/sample.muttrc.
The pattern is macro menu key_sequence [description]. That was clear right? Ok, maybe not. This
very simple macro will save an email to a mailbox called spam.
macro pager S "s+spam"
macro index S "s+spam"
First, one writes the word macro. This indicates that what follows will be a macro. That was easy,
right?
Next, the menu part. This refers to where you are in mutt. The word pager means that you're reading
the email, so you could move around in the particular email the same way you would with any
pager. The second line of this simple macro also binds the macro to the index--that is, while looking
at the list of messages. For example, if I open my FreeBSD-CURRENT mailbox and I have one
message highlighted, hitting shift+S (note that these macros are case-sensitive) will affect that
message, because I have used the index keyword. So, this macro will work if I am reading a piece of
email, or if I'm looking at my list of mail.
Next the capital S. That is the key that I am binding to the macro. You can use the control key,
escape key, etc. as well. Had I wanted to use ctl+s (that is, a lower case s) I would use \cs. A
backslash and c indicates the ctrl key. A backslash and e (\e) would be the escape key. However,
you can also use <esc> to indicate the escape key.
The samples provided with mutt will have things like <save-message>+spam<Enter>. However, I
haven't found all that to be necessary. Sometimes the end of line \n seems to be needed and
sometimes not. I haven't investigated macros too deeply, but it seems that if, in general, if a one
letter command would do something in mutt, it will work in a macro. For instance, in my example, I
just have s for save rather than the save-message thing. You'll note, if in mutt that hitting s will bring
up a dialog to save a message. So I can use it in my macro. The +spam indicates that it will be saved
to my $HOME/Mail/spam mailbox. (By default, mutt looks to save a message in $HOME/Mail/.)
As for key bindings, although the mutt manual refers you to the keybinding section, that seems to
have omissions. For example, they do show that both \e and <escape> can represent the escape key,
but they don't show the control key, nor does it say you can use <esc> rather than the full word
"escape".
It can sometimes be a bit tricky. In general, you attempt to duplicate what you would type while
mutt is open. The following is what I would type if I wanted to, while mutt is open, have the sa-learn
http://srobb.net/mutt.html
10/24
5/31/2015
mutt
program examine my spam mailbox and learn that everything in there is spam.
!sa-learn --spam --mbox ~/Mail/spam
(A shell command typed while in mutt needs an exclamation point typed before the command). If I
want to bind this command to a macro, let's say escape and s I need
macro index \es "!sa-learn --mbox --spam ~/Mail/spam<Enter>"
(I could also use macro pager but I tend to only use that particular command while looking at the
index of messages. There is also macro generic which seems to work anywhere in mutt.)
The command is double-quoted and ends with the word Enter in brackets. In this case, using \n for a
newline doesn't work. Also note that I typed an exclamation point within the double quotes. The
important thing here is that I am duplicating what I would type while mutt is open. I usually try to
get away with \n and if that doesn't work, then try again with Enter in brackets.
Sometimes, a macro might conflict with a default mutt macro or default terminal keybinding. You
can see your default keyboard shortcuts in mutt by typing ? while in most menus. For example, I
wanted to use ctl+s for something. It didn't work. However using <esc>s worked.
Some googling indicated that this was because ctl+s stops sending data to the terminal. Most Unix
and Unix-like terminals still support this. So, if a macro doesn't work, sometimes trying a different
keyboard combination might help--at least it should let you know if the problem is your syntax or
your chosen combination.
To use the alt key, you can set the following in your .muttrc
set meta_key=yes
If you do this, then using a keyboard macro beginning with \e will work with either the escape or the
alt key. It's usually turned off by default. As usual, you can check your system-wide Muttrc. If you
leave that set meta_key option at its default of no, then using \e will work with the escape key, but
not the alt key.
Another simple macro can be used to invoke getmail for those times when I don't feel like waiting
for the cronjob to run.
macro index G "!getmail\n" "Invoke getmail"
macro pager G "!getmail\n" "Invoke getmail"
Now, hitting shift G will run getmail though I've never been able to make this work with any rc file
besides the default getmailrc. That is, adding things like -rgmailrc to the macro didn't work.
I'm no expert on macros, but hopefully, this gives you enough of an idea of the syntax so that you
can begin using them for yourself
(Back to Contents)
Simple filtering
Mutt depends upon an MDA (Mail Delivery Agent) to deliver the mail. Both sendmail and postfix
will do the job on most Linux or BSD installations, however, they could be considered overkill for
the single user. Therefore, we're using maildrop. The other reason for using maildrop is to filter your
email. For example, on one box, although I have postfix to send mail, when it receives mail, that
mail is then sent to maildrop to be filtered.
If you get a reasonable amount of email, eventually you'll want to start filtering it.
(For those who prefer procmail, I have a page on it, that is basically an even quicker start than the
procmail quickstart guide here) However, it hasn't been maintained for years.
I use maildrop as my mail delivery agent. Its man pages and even its example pages make it seem
more complex than it is for our purposes, yet it is really quite simple.
Note for RedHat based distribution users (Fedora, CentOS, etc. Not applicable to Fedora 10 and
later.)
Prior to Fedora 10, RedHat based systems didn't have a package for maildrop. (In Fedora 10, just do
yum -y install maildrop.) I've built it from source without problems. However, Falko Timme has an
rpm, at least for Fedora 8, that can be gotten from one of his excellent tutorials at howtoforge.com.
The tutorial is here and includes a link to the rpm he created for Fedora 8. He also explains quite
clearly how one can simply compile the source rpm on their own machine as the maildrop people
are nice enough to include a specfile in the tarball.
I want to give my thanks to Tillman Hodgeson for his help with this. All mistakes are, of course, my
own, but at any rate, Tillman (whose web page can be found here) showed me how simple it is to
use.
First we're going to set up, in the home directory, a .mailfilter file, and only give permissions to the
owner. Open your favorite text editor. Let's start with a very simple rule. I belong to a busy mailing
list called nylug and I want all mail sent to it to go into its own mailbox in my $HOME/Mail
directory.
if (/^To: .*nylug/)
to Mail/IN-nylug
If using the Maildir format rather than Mail, you may have to add a trailing slash to the mailbox
name.
if (/^To: .*nylug/)
to Maildir/IN-nylug/
Don't put a blank or commented line between the if and to lines. If the to line is not on the line
http://srobb.net/mutt.html
11/24
5/31/2015
mutt
You see I used to send something to Oldmail and now want to send it to Newmail. Instead of
deleting the to Oldmail line, I've just commented it out. This won't work properly. Instead,
everything that hasn't yet been filtered will be affected by the "to Newmail" line and will go into the
Newmail box. If you want to leave the old line for reference then put it underneath the current rule,
e.g.,
if (/^To .*oldaddress/)
to Newmail
#
to Oldmail
Some mailing lists, such as nycbug and freebsd-questions, do things a bit differently. If one replies
to a nycbug post, the reply only goes to the original poster unless one cc's the mailing list.
In such a case, poster A sends his message to nycbug. A rule like the one above will catch it
(obviously, we change nylug to nycbug) However, replies to this post will have a To: line reading to
poster A, so the rule above would miss that post. A slightly more complex rule, however, will catch
it.
if (/^(From|To|cc|bcc): .*nycbug/)
to Mail/IN-nycbug
These rules are case insensitive which is a Good Thing (TM) if you are a careless typist.
One can also use Subject, From, or other header lines. The syntax is basically the same. If you are
just using one thing in the header, such as From, To, Subject, etc, then it would be
if (/^Subject: .*linux/)
to Mail/IN-linux
If you're using a slightly more complicated rule, trying to catch various parts of a header, like To, cc
subject, etc then use the various keywords inside a second set of parentheses separated by pipes as in
the nycbug example given above.
First the if, then the first parenthesis.
if (/^
Then the inner set of parentheses with the different conditions, separated by pipes.
if (/^(From|To|cc|bcc)
Then, finish the expression with the usual : .*whatever, close the expression--that is, type the final /
and close the parentheses
if (/^(From|To|cc|bcc): .*nycbug/)
Aside from multiple header possibilities, such as including To, cc and the like, you can have other
multiple conditions. If my friend John Paul Jones has three email accounts, all of which I want to go
in a mailbox named IN-jones, I could have a rule like
if (/^From: (.*john|.*jpjones|.*jjones)/)
to Mail/IN-jones
It's the same pattern. When there is more than one condition, put those multiple conditions in their
own set of parentheses, separated by pipes.
Although it's sometimes simpler and less prone to error to make a few separate entries, one can
combine various conditions. Like the nycbug rule given above, with FreeBSD-questions I want to
catch multiple header possibilities. Also, some people send mail to questions@freebsd.org and
others send it to freebsd-questions. So, the various multiple header possibilities go in one set of
parentheses and the other conditions in another set of parentheses, all surrounded by the usual (/^ /).
if (/^(From|To|cc|bcc): (.*questions@freebsd|.*freebsd-questions)/)
to Mail/IN-fbsd-questions
You might want to have a default personal inbox. In that case, after all the other rules put
if (/^To: john/)
to Mail/IN-personal
I like to have a default box to catch anything else so at the bottom of my .mailfilter file I have
DEFAULT="Mail/IN-Misc"
Note that in this case, one quotes the path to the IN-Misc folder.
Note that maildrop stops when it hits a match, so put your most frequently used rules first, and the
low traffic mailing lists towards the end.
If we want to run a command in our .mailfilter file, we can use xfilter. Say we want to send
everything through spamassassin first. The top line of our .mailfilter would read
xfilter "/usr/local/bin/spamassassin"
Actually, the SpamAssassin docs recommend using spamc for filtering mail so the line would read
xfilter "/usr/local/bin/spamc"
12/24
5/31/2015
mutt
brackets as shown) in the subject line. This can be a nuisance, so again, I use xfilter to send a
command to sed
xfilter "sed -e '/^Subject:.*\[despammed\]/s/\[despammed\]//g'"
Note that mailfilter should not have group or world permissions, so I set it read write for the owner.
chmod 600 .mailfilter
(One can also set it read only). For those who use SpamAssassin, you might want to put this rule at
the top.
#Run everything through SpamAssassin first
xfilter "/usr/local/bin/spamc"
if (/^X-Spam-Level: \*\*\*\*\*/)
to Mail/In-Spam
(This particular example is going to take anything with a score of 5 or higher and put it into a spam
mailbox).
I find that after making a new .mailfilter file (or editing an existing one) it's a good idea to run
getmail once with the -v (for verbose) flag. It will catch some (though not all) syntax errors in
.mailfilter and also complain about some careless mistakes, such as allowing group or world
permissions on the file. Sometimes, mailfilter won't work if the permissions aren't set to 500 or 600,
though I haven't tested that enough to be sure.
The last thing we have to do is edit our .getmail/getmailrc file (or files if we have multiple accounts.
At present the [destination] section reads
[destination]
type = Mboxrd
path = ~/Mail/IN-personal
unixfrom = True
We will change that to use an external program, in this case maildrop--in FreeBSD, it's in
/usr/local/bin so my revised [destination] section will read
[destination]
type = MDA_external
path = /usr/local/bin/maildrop
unixfrom = True
(If you used procmail instead, change maildrop to procmail. Also, once again take note of maildrop's
path on your system.)
(Back to Contents)
Reading mail
After you see that some mail has arrived open mutt by typing the command
mutt
Let's assume that I ran getmail with the -v flag and it indicated I received 7 messages. I'll open mutt
and see a menu at the top. The messages, if no other rule covered them, went into my IN-Misc box. I
then hit
c
(That's correct, just the letter c, to change directory)
I'll see a message
Open mailbox ('?' for list):
If I hit ? I will then see a list of my mailboxes. (The tab key also works) Although it doesn't tell me
how many messages in each one, it will show a 0 in front of any empty ones. Then, I just use the
arrow key (or vi commands, such as j and k) to highlight the mailbox that I want to examine.
If you set up mutt with mailfilter (or another filtering program) as mentioned above, everything will
go into one mailbox or another. This does, on some distros and O/S's cause mutt to give an error
message when opened, saying /var/mail/john: No such file or directory (errno = 2). This message is
harmless, but annoying. (It may, depending upon distro and/or O/S say /var/spool/mail/john). To get
rid of it, as root or with root privilege (in this case, we'll assume the message said /var/mail/john)
touch /var/mail/john
chown john:john /var/mail/john
chmod 600 /var/mail/john
You may also want to keep your sent mail in its own directory. In Gentoo, it automatically went to
.maildir-sent, where it was listed by numbers. Finding a sent message in there was difficult. So, I
would save all my messages to a directory in my .maildir called, obviously enough, SENT. To do
this, I added the following to my .muttrc file
fcc-hook .*. ~/.maildir/SENT
In RH or FreeBSD it would be ~/Mail/SENT
This is sufficient for my needs. Some people prefer to divide their sent mail into different
directories. If you wanted to do this you could insert a line like
http://srobb.net/mutt.html
13/24
5/31/2015
mutt
As the reader probably guessed, the ~s refers to the subject. As the subject line has two words in this
case, I put it within single quotes and the whole hook rule in double quotes. There are a variety of
patterns like this which mutt understands, listed in man(5) muttrc.
(Back to Contents)
Keeping addresses
To keep a list of addresses in mutt is pretty easy. Once again, open up your .muttrc file and add
these two lines
set alias_file=~/.mutt_aliases
source ~/.mutt_aliases
This tells mutt where to look for your aliases. This will serve as an address book. Now we create our
.mutt_aliases file. Open your favorite text editor. Suppose that you want to have freebsdquestions@freebsd.org and gentoo-user@gentoo.org in your address book. You also have a friend
John Smith who has the email of john@isp.com. You've been spoiled by Outlook Express, so you
don't want to type the whole address--you want to be able to type free for freebsd-questions, gen for
gentoo-user and John for your friend. We're going to put these three in our address book.
So, in our .mutt_aliases file we enter the lines
alias free
<freebsd-questions@freebsd.org>
alias gen
<gentoo-user@gentoo.org>
alias john John Smith <john@isp.com>
Now, if you open up mutt, and type m to send an email, if you type the alias in the the To: section,
mutt will send it to the desired address. (You won't see this until after you've edited the message--at
first, you would only see the alias that you entered). With the alias we did for John, if you type john
in the To: section, it will expand to the John Smith that you have in the center. If you need to simply
view your addresses, when you hit m and are given the To: line you can simply hit tab which will
show your alias list--you can scroll down to the name you want and hit enter.
Also, if you're looking at an email and want to add the person to your address book, you can just hit
a and mutt will take you through a dialog of creating an alias. Often, however, the last question will
be save to file /.mutt_aliases? You will have to change that from /.mutt_aliases to ~/.mutt_aliases.
The ~ refers to your home directory.
Recently, on a Fedora 15 installation, for whatever resaon, the a key wasn't mapped to the createalias function. This can be fixed permantly by adding it to your ~/.muttrc or on the fly by first hitting
a colon, : and then typing
bind a create-alias
The same line, if added to your ~/.muttrc, will then be in effect the next time you start mutt. You can
also specify index and pager, as mentioned in the macro section, e.g., bind index a create-alias
Default keybindings can be seen by hitting ? while in mutt. For example, in this particular Fedora
installation the term create-alias was there (which was how I reminded myself of the correct syntax)
but no letter was visible. The mutt.org docs give a list of default functions.
(Back to Contents)
14/24
5/31/2015
mutt
this article in the early 2000's when it was necessary to use subscribe--I have no idea when it
changed.
If just hitting L doesn't work on your version of mutt, add such lists to your .muttrc file. For
example, I belong to a few FreeBSD mailing lists. They all end with FreeBSD.org. In my .muttrc I
have the line
subscribe *freebsd.org
Now, if I reply to a posting on any of those lists and see no need for a separate, private reply to the
poster, I simply hit
L
(Note that it's capitalized). This will now post my reply to the mailing list, rather than the individual.
(Back to Contents)
Most of it should be self explanatory. As usual, we'll say the mail server is mail.example.com, the
username is john and the password is 1234. Assuming that the LDAP schema for the company uses
the ou of ourcompany, edit the lines above so that they read
$ldapserver = "mail.example.com";
$domain = "example.com";
$username = "john";
$password = "1234";
$basedn = "ou=ourcompany,dc=example,dc=com";
In some cases a company has a blanket user for the address book. If something like the above
doesn't work, you can try changing the user to a more ldap like entry.
$username = "ou=Addressbook,dc=example,dc=com";
Note that the above assumes you have a more or less typical AD or Exchange LDAP setup. Other
mail servers or LDAP schema may differ in which case you will have to edit according. For
example, the CommuniGate Pro server has a simplified builtin LDAP schema where the base dn is
simply cn=example.com. Hopefully, someone at your company knows the LDAP schema and can
tell you what to use. For binding to the directory, (that is, authenticating the username to the LDAP
server), mutt-ldap.pl uses the MS format. There is a line further down in the script which reads
$ldap->bind("$domain\\$username", password=>$password);
If your LDAP server uses a different form of bind (for example, many simply need username and
password) you may have to edit that line as well. If it just needed the username and password, then
that line would be changed to simply eliminate the "$domain\\ part, e.g., it would be changed to read
$ldap->bind($username", password=>$password);
In some cases, one has an LDAP server that doesn't require authentication to access the directory. In
that case, just fill in the ldapserver and basedn fields and comment out the others. Also comment out
the ldap bind line. Otherwise, though it will work, it will also give a message about an uninitialized
value in the file.
In addition, one can edit the output. As it is written, it will say
1 entries found
jsmith@example.com
You will see the following in the script towards the end
print($entry->get_value('mail'),"\t",
decode("UTF-8", $entry->get_value('cn')),"\tFrom
Exchange LDAP database\n");
The string From "Exchange LDAP database" can be edited or removed with no ill effects. I prefer to
remove it entirely so that I just see the email address and name.
One could even edit it, reversing the decode("UTF-8) and ('mail') lines so that the name appears
first. (Though I can't really see a reason to do that.) You can test that the script is working properly
by running a query with it.
mutt-ldap.pl smith
http://srobb.net/mutt.html
15/24
5/31/2015
mutt
The %s at the end refers to a query string. This means that you will run the mutt-ldap.pl script,
asking it to search for a string belonging to the name and/or email address that you request.
(For the complete beginner, a string refers to any group of characters).
If you haven't bound shift+Q to anything, it is the default macro for a query. In mutt, when you want
to check the ldap database for an address hit shift+Q and you will see Query:
Type in part of the name and mutt will show you a list of matching addresses. Use the arrow key to
highlight the desired address and mutt will use it.
If one wants to keep the address in their own ~/.mutt_aliases file, the following, admittedly very
kludgy script will do it.
#!/bin/sh
mutt-ldap.pl $1 |sed -n '2p' |awk '{print "alias","\"" $2,$3 "\"""\t" $1}'
For newcomers it runs the mutt-ldap.pl command. The $1 refers to a variable, in this case, the name,
for example, smith. As we've seen in mutt, this would return
1 entries found
jsmith@example.com
The sed -n '2p' will print the second line. We then pipe it to awk, which will do the editing we want.
We want "John Smith" in quotes here, hence the various "" with some escaped by \ to show awk that
yes, we want these quotes printed in the output, they aren't being used in the command.
By default awk uses spaces as field separators, so we want the entry to read
alias "John Smith"
jsmith@example.com
This isn't an article on awk (for a very good one see Daniel Robbins' article on Developer Works)
but basically we're inserting the word alias, swapping around what's printed out so that the name
goes before the email, then putting in a tab between the name (in quotes) and the email address.
To put it directory into your .mutt_alias file you could add >> ~/.mutt_aliases to the end of the script
so that it reads
mutt-ldap.pl $1 |sed -n '2p' |awk '{print "alias","\"" $2,$3 "\"""\t" $1}'>> ~/.mutt_aliases
(Be sure to use >>, not just >, otherwise you will overwrite your entire .mutt_aliases file. 2 >'s will
add it to the end. A single one will echo it to the existing file, completely overwriting the file.)
Until you're sure it's giving correct output, run it once as shown in the first example, without a >> at
the end, just to see what it will produce. Once you're happy with the output, you can start using it to
add the addresses directly to your .mutt_aliases by adding the >> ~/.mutt_aliases at the end. Note
that if your browser broke the lines, the entire line, beginning with mutt-ldap.pl and ending with
~/.mutt_aliases must be on one line.
It's certainly not necessary to do this if you trust your LDAP server, but it can save a few keystrokes
if you have frequently used addresses in your .mutt_aliases.
Experienced shell scripters or perl programmers can no doubt come up with better solutions, the
above is simply something I did in a hurry after deciding it would be useful.
(Back to Contents)
My getmail page goes into more detail. He creates a second rcfile in his ~/.getmail directory, called
getmailrc2. (In this case, it would be identical to the example given above, save that he would
change the server line to read pop.server.example1.com.
In other words, he's getting his example1.com account sent to the same place on his machine--he's
just telling getmail to poll a second server. Now, when getmail runs, it will poll both example.com's
pop server and example1.com's server.
John wants everything going to a particular domain to use one header. For example, he belongs to
mail@example1.com, mai12@example1.com and mail3@example1.com. He wants everything
going to all these mailing lists to be sent through example1.com rather than his default of
example.com He could make separate send-hooks for each list, however, he can also do it this way.
http://srobb.net/mutt.html
16/24
5/31/2015
mutt
works perfectly for him in mutt-1.5.6i, which is, at time of writing, the development version.
The mutt wiki's section on multiple accounts gives a different syntax. Its version would read
alternates ^john@isp1\\.com$ ^johnisp2\\.com$
For those unfamiliar with regular expressions, also called regex, the ^ in front of john means that the
address begins with john. The $ at the end indicates that the expression ends with com. The \\ before
the .com is to escape the period in .com. (In most regexes, one only uses one backslash to escape
special characters, but for some reason that I've forgotten, mutt requires two here.)
I've found that reverse_name can be iffy. If there are any send-hooks with my_hdr lines, it will
override reverse_name. For example, if I open mutt, and the first email I send is to one of the
FreeBSD mailing lists, I have a send-hook that uses example1.com. Now, I go to my personal mail
and there's a letter from a friend that was sent to example2.com. Even though the send-hook with the
my_hdr line shouldn't affect this second email, it will still use the return address of example1.com.
The send-hook's my_hdr will remain in effect for any emails that I send until overridden by a
different send-hook with a different my_hdr.
However, if I have two emails from two friends, neither of which have send-hook rules,
reverse_names will work as expected. It's a bit odd and I am not yet positive that I haven't
overlooked something in the man pages, but this rule seems to hold.
The my_hdr option itself is quite flexible. For example, if John wants to send mail from different
addresses but have everything come back to john@example.com he could add the following to his
.muttrc
my_hdr Reply-To: <john@example.com>
Now, unless over ridden by a particular send or folder hook, all emails will have the Reply-To: of
john@example.com The same can be done for any field in the header, cc, fcc, and all the rest.
As mentioned early in this article, If you have two conflicting rules in .muttrc, it will often follow
the last one. For example, on my work machine, I want everyone on the job to get emails from my
work address so I have the following
send-hook "workdomain" "my_hdr From: Scott <workemailaddie>"
However, there are a few users with whom I exchange emails in the evening. While I can boot up
my MS box and use our company's VPN, it's a nuisance. So, I wanted these users to reply to my
home email addie, which can also be used at work. However, I put these rules above the previous
rule, and it didn't work--I would have to set the reply-to manually. In other words if I have
send-hook "workuser" "my_hdr From: Scott <homemailaddie>"
send-hook "workdomain" "my_hdr From: Scott <workemailaddie>"
http://srobb.net/mutt.html
17/24
5/31/2015
mutt
it won't work. The user will still get email from my work address. If I reverse it however
send-hook "workdomain" "my_hdr From: Scott <workemailaddie>"
send-hook "workuser" "my_hdr From: Scott <homemailaddie>"
it works the way I want it to work. The man page explains this, saying that if there are multiple
matches for send-hooks, they will be processed in order. In other words, the final match will be the
one that is used. As mentioned above, fcc-hooks seem to work in the opposite manner, the first one
matched is used. There are also folder-hooks--like send-hooks, they are processed in order, so the
last matching folder-hook is used.
You can also have multiple conditions in a hook. For example, if I want all email to example.com
and example1.com to use a particular signature that I call SIG, I would do it this way.
send-hook "example.com|example1.com" "set signature="~/SIG"
I've seen posts where people say you can use ( example.com | example1.com ) however, in my
experience, using parentheses gives me an error. Also, if I leave a space after the pipe (the | symbol)
it doesn't work. In other words, if I do "example.com| example1.com" it won't work. I can do
example.com |example1.com, and it will work. The important thing seems to be to have no space
after the pipe character.
Don't forget that if you're using multiple accounts, you will have to add them to your .msmtprc. If
we use the .msmtprc that we described in the first section
account examplecom
host smtp.example.com
from john@example.com
account default : examplecom
we would change it to
account examplecom
host smtp.example.com
from john@example.com
account example1com
host smtp.example.com
from john@example1.com
account default : examplecom
(Back to Contents)
18/24
5/31/2015
mutt
A brief note on NetBSD. In FreeBSD, I use, rather than the word "black" the word "default." This
won't work in NetBSD. Also, NetBSD's default console is vt100 while FreeBSD's is cons25. Doing
in a sh shell or one of its derivatives (zsh, ksh, bash)
export TERM=cons25
in console will enable the colors. I've also found the oddity that in X, using rxvt, mutt won't use
colors. However, if I do the same exporting of the Xterm to cons25 it works without problem.
With a recent (September 2004, I think) FreeBSD ports revision of mutt, I ran into another issue. As
mentioned above, I would set the background to default. Suddenly, in console, rather than just the
lines of text appearing in the desired color, on a black background, the text would appear to be more
or less gray on a band of the indicated color. For example, if I have the From: line with red and
default, there would be a red band running across the screen with the text in a grayish sort of color.
However, if I changed default to black, that caused a problem in X, where my rxvt terminal has a
gray background. A minor annoyance, but an annoyance all the same. I solved it by making a silly
script that will swap two .muttrc files back and forth, one with a black background and one with a
default background. I only mention it here in case you run into a similar situation. (The silliness
about it is in the prompts, such as "Change it?" If I type no then it echoes, "Ok fool, fix it yourself."
I was in a bit of a whimsical mood when I wrote it.)
(This seems to be fixed as Feb. 2004, when upgrading to the latest FreeBSD port for mutt-devel.
Using "default" for background now gives me expected output in console.)
(Back to Contents)
Spell checking
While this is not specific to mutt, it's handy to be able to check your spelling before sending an
email. I use ispell--in RH, it's available as an rpm, in FreeBSD from the ports and in Gentoo from
portage. So, after it's installed add this line to your .muttrc
set ispell="/usr/bin/hunspell"
This used to be a program called ispell, but now the RH based distributions, at least, use hunspell.
CentOS' default /etc/Muttrc shows that hunspell is being used for ispell. If it is set to what you want
in the default /etc/Muttrc, you don't need to add it to your $HOME/.muttrc
Next, we're going to bind the F6 key to run it. So, open up .exrc or .vimrc, whichever you use and
add
map <F6> : !hunspell %<CR>: e %<CR>
One thing to note here--that is exactly what you type, a less than sign, <, CR, then a greater than
sign >. I didn't realize that would work (many thanks to Ian P. for letting me know, after seeing this
page), and used to use ^M, for the carriage return.
This is assuming that you have hunspell installed.
The ^M is actually a return character--in vi the way this would be done would be to hit ctrl+v and
then the return key--you'll see a ^M in the file. Either method works, but Ian's is far easier to
remember.
Now, when you want to check spelling, from command mode just hit F6 and ispell will run.
(Back to Contents)
were
set pgp_autosign=yes
set pgp_autoencrypt=yes
When I first upgraded from mutt-1.4x I would get a message that this was deprecated, and it gave
the suggested replacement of crypt_autosign and crypt_replyencrypt.
Here are the lines from my .muttrc dealing with pgp, taken from Mr. Miller's example.
http://srobb.net/mutt.html
19/24
5/31/2015
mutt
set pgp_encrypt_sign_command="pgpewrapng gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --en
set pgp_import_command="gpg --no-verbose --import -v %f"
set pgp_export_command="gpg --no-verbose --export --armor %r"
set pgp_verify_key_command="gpg --no-verbose --batch --fingerprint --check-sigs %r"
set pgp_list_pubring_command="gpg --no-verbose --batch --with-colons --list-keys %r"
set pgp_list_secring_command="gpg --no-verbose --batch --with-colons --list-secret-keys %r"
set crypt_autosign=yes
set pgp_sign_as=0xXXXXXXXX
set crypt_replyencrypt=yes
set pgp_timeout=1800
set pgp_good_sign="^gpg: Good signature from"
This will send the signature inline and is received as such by most mailing lists and Outlook
Express.
Also, you'll find that if simply install gnupg when sending mail, you'll get a warning message that
you're using insecure memory. This has to do with setting suid. (It's covered in the gnupg faq).
To fix it first find out where gpg lives.
which gpg
If you prefer the symbolic mode (using letters is the symbolic mode, using the octal numbers such as
4755 is the absolute mode), then the command is
chmod u+s /usr/local/bin/gpg
(Back to Contents)
Then, without making any changes to your .muttrc all emails would end with
-Scott
20/24
5/31/2015
mutt
appears in the header. (In muttrc it's called user_agent. To hide it, you would put set user_agent=no
in your muttrc.) To put something silly in there you would use
folder-hook . "my_hdr User-Agent:Jason Bourne"
Keep in mind that not everyone might have your sense of humor, so you might, rather than use the
folder-hook . use send-hooks to your friends instead lest such silliness go to your boss, or a potential
employer.
send-hook "my_friend" "my_hdr User-Agent: Austin Powers, man of mystery"
(Back to Contents)
to ~/.muttrc.
Another thing I picked up recently had to do with searching the SENT folder I have. The default
seems to be searching the From rather than To field. In SENT, if I was searching for something, I
wanted to look for the person to whom I'd sent the email. This required the following addition to my
.muttrc
folder-hook SENT 'set simple_search="~t %s | ~s %s"'
Speaking of searching, if I want to search a folder for key words in a message, it's done this way.
(This can be found by simply hitting a ? to get mutt's help)
Suppose I want to search my SENT directory for emails about samba. I open mutt, go to the sent
folder then hit <ESC>b. I'll then see a tilde and b (~b) and be asked for the search term. I can then
search the messages in that mailbox for the term.
Every so often, I like to clean out my sent folder. Let's say I have a thousand messages there,
ranging from January 2004 through July 2004. Suppose I want to get rid of the first 500 of them. I
can use tags. Note that in all the examples below, upper and lower case are important--if it's an
upper case letter than type it as such.
First I hit
T
To choose by index number, that is, the number of the messages, and to select the first 500 I then
type
~m 1-500
Now I hit
D
I then hit
~T
for tagged messages and when I exit mutt, they will be deleted. Doing it by date is similar. Note that
dates must be in the format DD/MM/YY, European style. If the month or year is left out, the current
month or year is assumed. So, suppose I want to delete everything from January through June.
~T
21/24
5/31/2015
mutt
~d
Then, as before, an upper case D for delete and all messages from January 1st, 2004 (01/01/04) to
June 30th, 2004 (30/06/04) will be deleted. There are some variations on this--this page is aimed at
the beginner so I'm only giving the most basic ideas. If you look at the mutt manual, usually
available in html format in /usr/share/doc or /usr/local/share/doc and look at the tags section and
searching by date, you can see a few shortcuts. As I mentioned, month and year, if not specified,
default to the current month and year. One can, rather than giving the entire range of dates, simply
indicate that everything up to a certain date or after a certain date should be selected. For example
-01/07/04
This would first tag all messages sent before July 1st, 2004, then delete them.
A ; (semicolon) will also indicate that you want to do something to all tagged messages. Suppose I
have 3,000 messages in my SENT mbox. Now I wish to move the oldest 2,000 to a new mbox called
ARCHIVE. I go into my SENT mbox and tag the first 2,000 as shown above, with T and then typing
~m 1-2000. Now, I type
;
I see
tag-
(The =<name> will be the name of the first of the tagged messages, so if message number one was
to robert, it would say =robert)
I backspace over the =<name> and type
~/Mail/ARCHIVE
(If I just type ARCHIVE, it will create a mbox ~/ARCHIVE rather than ~/Mail/ARCHIVE. In this
case, I want to save it in my ~/Mail directory.) It will ask
Create /home/<username>/Mail/ARCHIVE (yes/no)
The username being, obviously, my user name. If we stay with our example of john, it would say
/home/john/Mail/ARCHIVE. I hit y for yes, it will copy the messages. When I exit, mutt will ask if I
should delete the 1000 messages. If I hit yes, it will remove them from the SENT mbox.
As you can see, tags are quite handy.
Much of this can also be done without tags. For example, rather than tagging and then deleting, one
can just do
D
At that point one can use ~d -01/09/10 to specify deletion of all messages older than September 1st,
2010, or any other pattern such as ~m for messages, a date range, or almost any of the patterns that
we've already discussed. Note that you use an upper case D to signify deleting a match---a lower
case d will just delete the current message.
Sometimes, one wants to resend a message, either to edit it, or send to someone you forgot to cc or
whatever. If you open a message, say from the SENT mailbox, and wish to resend it as a new
message hit ESC e. This will resend it as a new message.
The folder and send hooks are incredibly flexible. For instance, suppose that you wish, whenever
you are in the freebsd-stable mailbox, that any message you send while browsing that mailbox goes
to the freebsd-stable mailing list. (Hopefully, you know that one does not thread-hijack--that is, you
don't take an email sent to a mailing list, simply change the subject line and hit reply. That messes
up anyone who views messages in a threaded format, as it doesn't really change the header
information. For a quick explanation of this, see a Faq I have for *nix newcomers.).
You can create a folder-hook entry in your .muttrc
folder-hook freebsd-stable "my_hdr To: freebsd-stable@freebsd.org"
Now, if you are browsing messages in your FreeBSD-STABLE mailbox, and hit m to create a new
http://srobb.net/mutt.html
22/24
5/31/2015
mutt
message, it will automatically be addressed to freebsd-stable@freebsd.org.
(Back to Contents)
This starts off with the sidebar not being visible. Hitting the b key when you open muttng makes it
visible. You would have to add your mailboxes to the mailboxes line. (I just put in two, to
demonstrate the syntax). Ctrl+n highlights the next mailbox, Ctl+p the previous one. To open the
highlighted mailbox, you hit Ctl+o.
In one installation, this didn't work as I expected. Although I was using mbox rather than Maildir
format, I would sometimes, with a new mailbox get the error message, for example, IN-FBSDcurrent is not a mailbox. Specifying the PATH as ~/Mail/IN-FBSD-current in the sidebar section
fixed this.
Also, in one case, the Ctl+0 wouldn't open the Mailbox. Nothing happened. I just changed it from
\CO to \CL and it worked. I assume there is some other setting somewhere in the defaults or my
.muttrc. I didn't find it worth troubleshooting so when 2 minutes of googling didn't bring me a quick
answer, I just changed CO to CL. Ctl+L would open the mailbox as expected.
For example, say I have 3 mailboxes, Personal, Misc and FreeBSD. Suppose I only have two of
them listed in the mailboxes = line, Personal and Misc.
Now, I start mutt. I have the sidebar off by default, and hit c to view my mailboxes. I then get the
message hit ? for list. If I do so, then it shows me my ~/Mail directory and all the mailboxes.
However, if I hit tab, and there is a new message in Misc, it will first want to open Misc. If there are
no new messages in Misc or Personal, the two mailboxes listed in the mailbox line, then, even if
there is a new message in the FreeBSD mailbox, it will act as mutt does, and again just show me the
entire ~/Mail directory.
This is the behavior that I actually prefer, so, I set my mailboxes = line to null, in other words, my
.muttrc has the line
mailboxes =""
This means that no mailboxes will show up if I use the sidebar, but as mentioned above, I found it
an interesting toy but quickly tired of it. If I went back to using the sidebar, then I would have to add
all mailboxes to the mailboxes line.
I'm making this sound more complex than it actually is--also, we're talking about one or two
keystrokes. At any rate, if you wish to use the sidebar from time to time, add all mailboxes in your
~/Mail or ~/Maildir to the mailboxes = line. If you just wish to open up your Mail or Maildir
directory when you hit c, then tab, set it to null, by using the mailboxes ="" line shown above. If you
don't, at least in FreeBSD as of June 2005, rather than opening your ~/Mail directory, it will go to
/var/spool/mail. (This has also been covered above--until you start setting up various filtering rules,
that's the default location for any mail you receive.)
In mutt 1.5.x lines in the .muttrc file dealing with pgp have to be changed. If not, you'll get error
messages, (although it should still work, if I remember correctly, these lines are just deprecated, not
yet removed).
I have suggested above that the reader use Justin Miller's file. It has the lines
set pgp_autosign=yes
set pgp_replyencrypt=yes
http://srobb.net/mutt.html
23/24
5/31/2015
mutt
Another handy mutt trick is if you need to send an attachment from, for example, a shell script. The
mail command can do this of course, but it's rather non-trivial. With mutt, suppose you had to send
john@example.com a document called file.doc. If you are going to send that without any message,
and the subject line of "attached docs" the command would be
mutt -a file.doc -s "attached docs" john@example.com
If you wanted to send the message, message.txt to john as well, the command would be
mutt -a file.doc -s "attached docs" john@example.com < message.txt
If you get an error like unable to attach file separate the recepient's address with double dashes and a
space for example
mutt -a file.doc -s "test" -- john@example.com
Another way is to just make sure the attachment is at the end of the line, for example
mutt -s "test" john@example.com -a file.doc
This doesn't seem to work completely non-interactively--it will open a window with the address you
specified, and require some keyboard input, going to the compose window (even if you have already
specified a textfile for input) and requiring :x or :wq before getting to the send screen, where you
manually have to send. I haven't yet found a way to completely automate it.
To attach a file when using mutt normally (as opposed to the method above with a script) simply hit
the "a" key (without the quotes.) You will then be asked for the name of the file you want to attach.
If you change your mind about the attachment before sending the email, highlight the attachment
and hit D for detach. As always in Unix, case is important and this has to be an upper case D.
Sometimes, for example, at a job where everyone else uses Outlook, and includes images inline, you
may want to do this with mutt. The world is changing and most people use html mail. I'll avoid my
rants on this, and simply mention that if you want your attachment in line, rather than showing as an
attachment, you can do this. After having hit a for attach, and seeing the file name (with an A to its
left, to indicate that it's an attachment, hit ctl+d. This, in composing mode, will "toggle disposition"
meaning it will change a mime type from attached to inline. You will see the A change to an I, and
the attachment will now appear to the viewer as part of the email, rather than an attached file. I
haven't figured out a way to get it to appear above the signature, however--it will appear below your
signature.
That's about it. The above only serves as an introduction, but gives you an idea of how to get started
with mutt.
The Mutt online manual is an excellent next step. It's also usually available in /usr/doc/.
I also have a few brief guides to maildrop, getmail and fetchmail (though the fetchmail one is quite
dated) at our qnd-guides site.
last modified: 04/02/2015 18:29:38
url:http://srobb.net/mutt.html
http://srobb.net/mutt.html
24/24