pantz.org banner
Configuration of the Mutt e-mail reader
Posted on 09-13-2005 00:13:00 UTC | Updated on 09-13-2005 00:13:00 UTC
Section: /software/mutt/ | Permanent Link

The following is the config files for the suite of programs I use to read mail in Mutt. Each section will have a description about the program and file. The users name will be referred to as "pantz". These config file for Mutt have been tested on mutt version 1.5.9i. The whole setup was done on a Debian Linux machine.

Fetchmail is a program that can retrieve mail from a POP, IMAP, ETRN, or ODMR-capable server. You use this program to retrieve your mail from the server. It is your MRA mail retrieval agent. Set it as service to run as a daemon to check mail. Usually if it was installed as a package then there is a script in /etc/init.d that takes care of this. It just needs to be turned on. If not you just execute it and it runs as a daemon. Any subsequent time it is run it just checks your mail.

The file .fetchmailrc goes in your home directory. An example of one is below.

# time period to check mail
set daemon 120

# where to keep a log of fetching mail (if you want)
set logfile /home/pantz/fetchmail.log

# server that has your mail and protocol to use to get it
poll 192.168.1.1 proto POP3

# mail account username, password, and local system username to deliver mail
# put the word "ssl" after the second "pantz" below if you want to connect with ssl
user "pantz" pass blah1234 is "pantz"

# get all mail on server
fetchall

# don't keep it on the server. delete it.
nokeep

# send it to procmail (mail delivery agent - MDA) for delivery
mda "/usr/bin/procmail -d %T";

Next is our mail delivery agent (MDA) Procmail. Procmail's lot in life is to process email. It is a whole scripting language setup to just process mail. Below are some examples and also just the basics you need to get your email from fetchmail into a file for viewing with fetchmail. You have to set the different variables for your specific setup.

The file .procmailrc goes in your home dir. An example of one is below.

#########################################
########  .procmail rules  ##############
#########################################

### System variables
DROPPRIVS=yes
LINEBUF=8192
PATH=$HOME/bin:/usr/bin:/sbin:/usr/local/bin:/usr/local/sbin
SHELL="/bin/sh"

### De-bugging logs
#VERBOSE=yes
#LOGABSTRACT=all
LOGFILE=$HOME/procmail.log

### Macros
#SUBJ=`formail -zx Subject:`

### Mail Folders

# Define different files to put the emails in using variables.
# MAILDIR is a variable that tells procmail what directory our mail folders are in.
MAILDIR =$HOME/Mail
INBOX =$MAILDIR/inbox
SAVE =$MAILDIR/save
SPAM =$MAILDIR/spam
ARCHIVE =$MAILDIR/archive

############################################
######### Procmail Filters #################
############################################

### Check for duplicate email's. If it finds one just kill it.
### Keeps a Message ID cache in a file using the program formail.
:0 Wh:dup
 | formail -D 8192 $MAILDIR/procmailrc.msgid.cache

###The :0 means the start of a new recipe.
###The second : tells procmail to use a lockfile while executing the actions in this
###recipe - otherwise, if you were to get 2 emails at once, they might both try and
###write to the file at once (and your mailbox could get corrupted).
###The next line specifies a folder to file the mail into - in this case, a file called inbox
### Most basic setup is just take the mail from fetchmail and put it in your inbox.
:0:
${INBOX}

### Another setup is to send a copy of all emails to the archive file
### then play a sound and put a copy in the inbox file.
### In Mutt there is a send-hook that copies all sent mail to the same (archive) file.
#:0
# {
# :0 c
# ${ARCHIVE}
# :0 c
# | play -v 3 /home/pantz/sounds/c813.wav
# :0
# ${INBOX}
# }

#### Examples ####

### Look if email is to a specific email address and from a certain person or domain. 
### If so drop it into a certain mail file.
### If this mail matches mail coming in then play a wav sound and put a copy in the personal and inbox mail files.
#:0
# * ^(To:|Cc:).*(pantz@blahblahblah\.blahblah\.blah\.org)
# * ^From:.*(@domain1.org|@domain2.com|[email protected]|[email protected])
#        {
#        :0 c
#        ${PERSONAL}
#        :0 c
#        | play /home/pantz/sounds/picarddoorchime.wav
#        :0
#        ${INBOX}
#        }

### Look for a certain word in a subject line. Play a certian sound and put it in the inbox file.
#:0 D
#  * ^Subject:.*(DOWN|PROBLEM|CRITICAL)
#        {
#        :0 c
#        | play -v 4 /home/pantz/sounds/redalert.wav
#        :0
#        ${INBOX}
#        }

### Basic bogofilter setup is if mail is found to be spam 
### put it in the spam folder and stop. All other messages are 
### considered good so put a copy in the archive and then the
### inbox.
### Below is the cron line for bogofilter spam databases
### */40 *   *   *   *   rm /home/pantz/wordlist.db;bogofilter -s < /home/pantz/Mail/spam;bogofilter -n < /home/pantz/Mail/archive

#:0
#{
#  :0fw
#  | /usr/bin/bogofilter -p -e
#  :0
#  * ^X-Bogosity:.(Spam|Yes)
#  ${SPAM}
#  :0
#  * ^X-Bogosity:.(Ham|Unsure|No)
#  {
#    :0 c
#   ${ARCHIVE}
#   :0
#   ${INBOX}
#  }
#}

### Using bogofilter to check for spam (if its installed).
### Check for incoming mail that matches your email address(s).
### Send a copy to bogofiter. If it comes back marked as spam
### then send it to the spam folder and stop. If not anything 
### not matching the "From" or "Subject" filter lines are copied
### to the archive folder. A sound is played and the message is 
### put into the inbox.
#:0
#  * ^(To:|Cc:).*(pantz@|pantz2@)
#        {
#        :0fw
#        | /usr/bin/bogofilter -p -e
#        :0
#        * ^X-Bogosity:.(Spam|Yes)
#        ${SPAM}
#        :0
#        * ^X-Bogosity:.(Ham|Unsure|No)
#                {
#                :0 Dc
#                * !^From:.*(pantz@blahblahblah\.blahblah\.blah\.org)
#                * !^Subject:.*(REBOOT|3DM|UP|RECOVERY|Statistics)
#                ${ARCHIVE}
#                :0 c
#                | play /home/pantz/sounds/exclaim.wav
#                :0
#                ${INBOX}
#                }
#        }

### Cron line to teach bogofilter good and bad.
### */40 *   *   *   *   rm /home/pantz/wordlist.db;bogofilter -s < /home/pantz/Mail/spam;bogofilter -n < /home/pantz/Mail/archive 

Mutt is your mail user agent. This is what you going to use to view your email. The setup below is just my preference on how I like to use mutt. Adjust the settings to taste.

The file .muttrc must go in your home directory. An example of the file is below.

# System configuration file for Mutt
# Set terminal to back background white text.

#######################################################
###  Pager
#######################################################
ignore *
unignore X-Bogosity date From: to cc subject reply-to
# Order to display the headers in
hdr_order X-Bogosity From: Reply-To: To: Cc: Date: Subject:


#######################################################
###  Macros
#######################################################
# imitate the old search-body function
macro index \eb '/~b ' 'search in message bodies'

# simluate the old url menu
macro index \cb |urlview\n 'call urlview to extract URLs out of a message'
macro pager \cb |urlview\n 'call urlview to extract URLs out of a message'

# change mailbox and other keys bound to actions
macro index   <f5>  'c =inbox^M'
macro pager   <f5>  'c =inbox^M'
macro index   <f6>  'c =archive^M'
macro pager   <f6>  'c =archive^M'
macro index   <f7>  'c =save^M'
macro pager   <f7>  'c =save^M'
macro index   <f8>  'c =spam^M'
macro pager   <f8>  'c =spam^M'
macro generic <f12> '!fetchmail^M' # run fetchmail to get mail. NOW!
macro pager   <f12> '!fetchmail^M' # run fetchmail to get mail. NOW!
macro index d '<delete-message>$' # delete message immediately then refresh view.
macro pager d '<delete-message>$' # delete message immediately then refresh view.
macro attach s <save-entry><bol>/home/pantz/tmp/ #directory to save attachments

#######################################################
###  Headers
#######################################################
# Default From: line
my_hdr From: [email protected] (Mr Pantz)
my_hdr Reply-To: [email protected] (Mr Pantz)
#my_hdr Errors-To: [email protected]
#my_hdr X-Header0: *****    Cool header 1          *****
#my_hdr X-Header1: ****     Cool header 2           ****

#Fun with Outlook users. Pop a funny warning box, set highest priority, set date 3 days back.
#my_hdr X-Message-Flag: OUTLOOK WARNING!! Install Linux
#my_hdr Reply-By: `date --date="-3 days"`
#my_hdr X-MSMail-Priority: High 

#######################################################
###  Colors
#######################################################
color quoted yellow default
color quoted1   cyan       default
color quoted2   magenta    default
color quoted3   green      default
color quoted4   red        default
color signature blue default
color normal white black
color status brightgreen blue
color indicator brightyellow black
color error red black
color tree yellow black
color attachment blue  default # MIME attachments or PGP expression
color index cyan black (joseph)
color index     green          default  ~T      # Tagged
color index     red            default  ~D      # Deleted
color header green black .*
color header brightred  black (^From\:|^Reply-To\:)
color header brightyellow black (^To\:|^cc\:|^Cc\:)

color body      magenta      default "(ftp|http)://[^ ]+" # point out URLs
color body      magenta      default [-a-z_0-9.]+@[-a-z_0-9.]+    # e-mail addresses
color body      brightyellow default " [;=:8]-*[])>]"       # :-) etc...
color body      brightblue   default " [;=:8]-*[(<|/\]"     # :-( etc...
color body      brightgreen  default "^(gpg: )?Good signature"
color body      brightgreen  default "^(gpg: )?encrypted"
color body      brightred    default "^(gpg: )?Bad signature"
color body      red          default "^(gpg: )?warning:"
color body      red          default "^(gpg: ).*failed:"

color message    magenta        default # info messages
color search     brightyellow   red     # search matches
color tilde      brightmagenta  default # ~ at bottom of msg
color markers    red            default # + at beginning of wrapped lines
color hdrdefault cyan           default # default header lines
color bold       red            default # hiliting bold patterns in body
color underline  green          default # hiliting underlined patterns in body

#######################################################
###  Options
#######################################################
bind editor <BackSpace> backspace
push <show-version>

source ~/Mail/addressbook  # email address book location
mailboxes ~/Mail/inbox # inbox file location

auto_view text/html # Autoview attachments
unset abort_nosubject
unset abort_unmodified
  set allow_8bit
  set alias_file="~/Mail/addressbook" # same as email address file
  set ascii_chars
unset arrow_cursor
  set autoedit
unset beep
unset beep_new
unset bounce_delivered
  set check_new
unset confirmappend
  set copy
  set delete
 #set editor = "vi -c 'set textwidth=72'" # uncomment if you use vi
  set editor = "nano -s ispell -r 80" # set the editor you will use to edit email
  set envelope_from
  set fast_reply
unset fcc_attach
  set folder="~/Mail" # set the directory where your mail files are kept
  set forward_decode
  set forward_format="Fwd: %s"
  set help
  set hostname="yourhostsname.domain.lan"
unset implicit_autoview # Autoview attachments
  set include
  set indent_string=">"
  set index_format="%3C %Z %(%D) %-27.27L (%4c) %s"
  set ispell="clear;aspell -e -c"
  set mailcap_path=~/.mailcap:/etc/mailcap # program list to open attachments
  set mailcap_sanitize
  set mail_check=2
unset markers
unset mark_old
unset metoo
  set menu_scroll
  set mime_forward_decode #decoding of complex MIME messages into text/plain when forwarding a message
  set mime_forward_rest # attachments which cannot be decoded in a reasonably will be attached to a new  message 
  set pager="builtin"
  set pager_format=""
  set pager_index_lines=10
  set pager_stop
unset postpone
  set postponed="~/Mail/postponed" # file for postponed email
  set print=ask-no
  set read_inc=2
  set reply_to
unset reply_self
  set sig_dashes
unset sig_on_top
  set smart_wrap
  set sort_aux=date-received
  set sort=threads
  set status_format="--FOLDER: %f --SIZE: %l%?L? (%L)?  --MESSAGES: %?m?%m total?%?M?, %M shown?%?n?, %n new?%?t?, %t tagged?%?d?, %d marked for deletion? %>--"
  set sort_re
  set status_on_top
unset strict_threads
unset suspend
  set tilde
  set timeout=2
  set thorough_search
unset user_agent
unset wait_key
unset write_bcc

#######################################################
###  Hooks
#######################################################
#send-hook . "set signature=~/Mail/signature" # uncomment to use a signature file
#send-hook . 'unset pgp_autoencrypt pgp_autosign'
send-hook . 'set record="~/Mail/archive"' # mail sent by me gets copied to archive file
#send-hook friend1@here\.org 'set record="~/Mail/archive_personal"' # certain sent mail gets copied to other files
#send-hook '~s "spam complaint"' 'set record=spam' # if subject says "spam complaint" copy to file spam
#send-hook (majordomo|mdom|request|subscribe)@ 'set signature=""' # list's don't need a signature
## if going to a certain email address when replying set reply info to different info
send-hook 'person@blah\.example\.com' 'my_hdr From: Firstname Lastname '
send-hook 'person@blah\.example\.com' 'my_hdr Reply-To: Firstname Lastname '
#folder-hook archive push 'D~r>14d!~F\n' # Delete mail 14 days or older 

#######################################################
###  GPG Hooks
#######################################################
#send-hook friend1@here\.org 'set pgp_autosign'
#pgp-hook friend1@here\.org FB373AFE

## The following options are only valid if you have
## compiled in PGP support

#my_hdr X-GPG-Key-Server: http://pgp.mit.edu
#my_hdr X-GPG-Key-FingerPrint: DA2F 6D5F 052B 0180 6E12  F62D 85E6 9276 59CC E5B6

#set pgp_decode_command="gpg %?p?--passphrase-fd 0? --no-verbose --batch --output - %f"
#set pgp_verify_command="gpg --no-verbose --batch --output - --verify %s %f"
#set pgp_decrypt_command="gpg --passphrase-fd 0 --no-verbose --batch --output - %f"
#set pgp_sign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --detach-sign --textmode %?a?-u %a? %f"
#set pgp_clearsign_command="gpg --no-verbose --batch --output - --passphrase-fd 0 --armor --textmode --clearsign %?a?-u %a? %f"
#set pgp_encrypt_only_command="/usr/lib/mutt/pgpewrap gpg --batch --quiet --no-verbose --output - --encrypt --textmode --armor --always-trust --encrypt-to 59CCE5B6 -- -r 
%r -- %f"
#set pgp_encrypt_sign_command="/usr/lib/mutt/pgpewrap gpg --passphrase-fd 0 --batch --quiet --no-verbose --textmode --output - --encrypt --sign %?a?-u %a? --armor 
--always-trust --encrypt-to 59CCE5B6 -- -r %r -- %f"
#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"
#unset pgp_retainable_sigs
#set pgp_ignore_subkeys
#set pgp_verify_sig=yes
#set pgp_create_traditional=no
#set pgp_autosign=no
#set pgp_autoencrypt=no
#set pgp_sign_as=59CCE5B6
#set pgp_replysignencrypted
#set pgp_replyencrypt=yes
#set pgp_replysign=yes
#set pgp_timeout=3600
#set pgp_good_sign="^gpg: Good signature from"

A mailcap file is a configuration file that maps MIME types to external viewers. An example would be mapping MIME type image/gif to the image viewer "qiv". This is needed for you to be able to open attachemnts with the correct program from inside mutt.

The file .mailcap goes in your home dir. An example of one is below.

# This is a simple example mailcap file.
# Lines starting with '#' are comments.

# This maps all types of audio data (audio/basic, audio/x-aiff,
# etc.) to the viewer 'showaudio'.  Note that '%s' means 'put the
# datafile name here when the viewer is executed'.
audio/*; showaudio %s

# This maps all types of images (image/gif, image/jpeg, etc.)
# to the viewer 'xv'.
image/*; qiv %s

# This maps MPEG video data to the viewer 'mpeg_play'.
video/mpeg; mplayer %s

# This maps all types of video *other than MPEG* to the viewer
# 'genericmovie'.
video/*; mplayer %s

# keep adding as you like
application/postscript; ghostview %s
application/x-dvi; xdvi %s
text/html; lynx %s; nametemplate=%s.html
application/msword;abiword %s
image/x-eps;xpdf '%s' -caption "PS/PDF Viewer"  ;test=test "$DISPLAY" != ""

Here is the email addresses file for mutt. Just put in the alias for the person (what you will type in mutt to send them mail). Then their name and email address in the format below.

The file addresses can go anywhere on your system your user has access to the file. I suggest your home directory. An example of it is below.

# Aliases file format:
# alias joe Joe Blow 
#
#
alias homekim Kim Johnson <[email protected]>
alias homeroger Roger Chen <[email protected]>

Now we need a way to send out email. We are going to use Postfix as our mail transfer agent. It's an easy one file setup. Configure and drop in the .cf file and start up postfix. Don't forget to set your relayhost in the file. Hint: that's your ISP's outgoing mail server. If you try to use your server to sendout the mail it is likey to get blocked by blacklists if your using a residential account.

The file main.cf for Postfix resides in the /etc/postfix directory. So put it there.

biff = no
recipient_delimiter = +
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
program_directory = /usr/lib/postfix
inet_interfaces = 127.0.0.1

### No one needs to know what we run. So We'll give them this.
mail_name = Mail Daemon
smtpd_banner = $mail_name. All Spam Is Reported. ESMTP

### Who delivers the mail (never root for security).
setgid_group = postdrop

### If the user does not exist, send mail to this user
luser_relay = root

### The myorigin parameter specifies the domain that appears in mail that is posted on this machine.
append_dot_mydomain = no
append_at_myorigin = yes

#If you don't want postfix getting it's hostname from the current host you can set it. 
#myhostname = host.domain.tld

# If your comming from an home ISP you might need to change this to the hostname they give you.
myorigin = someisp.net

### alias's
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

### The mydestination parameter specifies what domains this machine will deliver locally, instead
### of forwarding to another machine. The default is to receive mail for the machine itself.
mydestination = localhost.localdomain, ,localhost

### Relay Host this mail server should send its mail to. Possibly your ISP's mail server. The smarthost.
relayhost = smtp.yourisp.com

### External Networks to accept RELAYED mail from.
mynetworks = 127.0.0.0/8

### Where to send mail that is delivered locally.
mailbox_command = procmail -a "$EXTENSION"

### How much of the message in bytes will be bounced back to the sender.
bounce_size_limit = 2000

### No limit on mailbox size.
mailbox_size_limit = 0

### Limit sent/recieved emails to 100 Megs "(header+body+attachment)x(mime-encoding) <= 100 meg"
message_size_limit = 102400000

### How long do messages stay in the queue before being sent back to the sender. (in days)
### By default, postfix attempts to resend the message every (1000 secs)x(# attempts)x(days).
maximal_queue_lifetime = 4h

### Parrallel delivery force (local=2 and dest=20 are aggressive)
local_destination_concurrency_limit = 20
default_destination_concurrency_limit = 20

### Max flow rate (1 sec delay per 50 emails/sec over the number of emails delivered/sec)
in_flow_delay = 1s

###Clients must send a HELO (or EHLO) command at the beginning of an SMTP session.
smtpd_helo_required = yes
strict_rfc821_envelopes = yes

### No one needs to ask our server who is on it. If you do, you get smacked with the tarpit and then an error 450.
disable_vrfy_command = yes

Extra notes and hints

#bash alias I use to start fetchmail. Then start and send mutt to the inbox.
#Put in ~/.bashrc
alias m='clear;fetchmail;mutt -f =inbox'

---------------------
Some useful mutt keys
---------------------
d	- Delete highlighted message
F1	- Help
Y	- Send message
$	- Refresh screen (sync mailbox) after action
?	- Command help
o	- Sort messages in index mode
g	- Group reply
t	- Tag a message
;	- Perform a action on a tagged message (like delete tagged). Try t then ; then d.
e	- Edit a mail message (attachement) after you've edited it before
/	- Search text in the index (names,subject)
<esc> b - Search in body of message

Reddit!

Related stories


RSS Feed RSS feed logo

About


3com

3ware

alsa

alsactl

alsamixer

amd

android

apache

areca

arm

ati

auditd

awk

badblocks

bash

bind

bios

bonnie

cable

carp

cat5

cdrom

cellphone

centos

chart

chrome

chromebook

cifs

cisco

cloudera

comcast

commands

comodo

compiz-fusion

corsair

cpufreq

cpufrequtils

cpuspeed

cron

crontab

crossover

cu

cups

cvs

database

dbus

dd

dd_rescue

ddclient

debian

decimal

dhclient

dhcp

diagnostic

diskexplorer

disks

dkim

dns

dos

dovecot

drac

dsniff

dvdauthor

e-mail

echo

editor

emerald

encryption

ethernet

expect

ext3

ext4

fat32

fedora

fetchmail

fiber

filesystems

firefox

firewall

flac

flexlm

floppy

flowtools

fonts

format

freebsd

ftp

gdm

gmail

gnome

google

gpg

greasemonkey

greylisting

growisofs

grub

hacking

hadoop

harddrive

hba

hex

hfsc

html

html5

http

https

hulu

idl

ie

ilo

intel

ios

iperf

ipmi

iptables

ipv6

irix

javascript

kde

kernel

kickstart

kmail

kprinter

krecord

kubuntu

kvm

lame

ldap

linux

logfile

lp

lpq

lpr

maradns

matlab

memory

mencoder

mhdd

mkinitrd

mkisofs

moinmoin

motherboard

mouse

movemail

mplayer

multitail

mutt

myodbc

mysql

mythtv

nagios

nameserver

netflix

netflow

nginx

nic

ntfs

ntp

nvidia

odbc

openbsd

openntpd

openoffice

openssh

openssl

openvpn

opteron

parted

partimage

patch

perl

pf

pfflowd

pfsync

photorec

php

pop3

pop3s

ports

postfix

power

procmail

proftpd

proxy

pulseaudio

putty

pxe

python

qemu

r-studio

raid

recovery

redhat

router

rpc

rsync

ruby

saltstack

samba

schedule

screen

scsi

seagate

seatools

sed

sendmail

sgi

shell

siw

smtp

snort

solaris

soundcard

sox

spam

spamd

spf

spotify

sql

sqlite

squid

srs

ssh

ssh.com

ssl

su

subnet

subversion

sudo

sun

supermicro

switches

symbols

syslinux

syslog

systemd

systemrescuecd

t1

tcpip

tcpwrappers

telnet

terminal

testdisk

tftp

thttpd

thunderbird

timezone

ting

tls

tools

tr

trac

tuning

tunnel

ubuntu

unbound

vi

vpn

wget

wiki

windows

windowsxp

wireless

wpa_supplicant

x

xauth

xfree86

xfs

xinearama

xmms

youtube

zdump

zeromq

zic

zlib