This page was created from the Ubuntu Forums guide: [Howto] Use Mutt with Gmail, where support is still available for this wiki page. Thanks to the author of this guide for his kind permission to use the material on this page!


This page is a guide to using the email client Mutt to send, receive and read email under Ubuntu using a Gmail account as a relay. It describes POP2 over SSL rather than the increasingly popular IMAP. It has been tested and extensively used under Ubuntu Oneiric Ocelot. There are a few steps involved but if followed carefully and in sequence you will soon be using Mutt successfully with your Gmail account. If this is your first attempt at this guide I would recommend following the sequence of the page, otherwise feel free to navigate as you please!

Introducing John

To avoid confusion in editing the many configuration files involved in this setup I will describe the setup of mutt and gmail for my new friend John, who has been borrowed from this guide's big brother. John's details are as follows:

Gmail Address:
Gmail Password:       rover
Computer Username:    john

Please remember, Gentle Reader, to substitute your own details for John's. Hopefully this will lessen the confusion that I have unintentionally created with older versions of this page!

Introducing vim

I have been somewhat taken to task for throwing vim into this guide without too much warning, for which my apologies to all. vim is the text editor that I feel suits mutt the best but a little preparation is a good idea before launching straight into it. Download vim from the repository as follows:

sudo apt-get install vim

and once vim is installed run through the builtin tutorial by simply running:


It may take a little time to come to grips with this great editor but trust me it is time well spent. For those who find it all a little hard there is always nano or pico!

Further setup

Mutt does not work on its own so before getting to grips with mutt itself w will need to install and configure a few other applications:

SSL Tools

Gmail uses the POP3-over-SSL protocol to protect the transmission of username and password over the Internet. You will need to install both open SSL and a certificate pack from the repository as follows:

sudo apt-get install openssl ca-certificates

Later you will need to add the necessary SSL instructions to Fetchmail, but the next step is to install the software to send mail from your computer to the server: msmtp.


msmtp is a great and wonderfully reliable way to move mail from your computer. Download it from the repository as follows:

sudo apt-get install msmtp

There is a single configuration file to be altered: $HOME/.msmtprc. It can be created and permissions set as follows:

touch $HOME/.msmtprc && \
touch $HOME/.msmtp.log && \
chmod 0600 $HOME/.msmtprc

Below is the required configuration for a Gmail server:

account default              
port 587                     
from ""   
tls on                       
tls_starttls on              
tls_trust_file /etc/ssl/certs/ca-certificates.crt
auth on                     
user "john.example"       
password "rover"       
logfile ~/.msmtp.log

Now to setup Fetchmail:


Fetchmail is great tool to download mail from Gmail. Download it from the repository as follows:

sudo apt-get install fetchmail

Once again a single configuration file is required and so you will need to create ~/.fetchmailrc as follows:

vim ~/.fetchmailrc

The following configuration allow Fetchmail to access and fetch email from Gmail, leave a copy of the mail on the Gmail server and pass the mail to Procmail on your local machine. The SSL configuration is included here as well:

with proto POP3                      
user ""        
there with password "rover"        
is "john" here                              
mda "/usr/bin/procmail -d %T"        
no keep                                 
sslcertpath /etc/ssl/certs

All done except as a final touch, since the username and password are openly in this file,you will need to make the file readable only by the file owner. If this is not done Fetchmail will not even run:

chmod 600 ~/.fetchmailrc

Now would be a good to time to make sure you have POP forwarding enabled in your Gmail account. You will find this in: Settings - Forwarding and POP. Note also that Gmail has a little oddity in regard to the "keep" and "nokeep" command of Fetchmail. You cannot remove mail from Gmail servers via POP3 but you can choose to have your messages archived, kept or deleted once they have been downloaded via POP3. This is a Gmail setting hidden in Settings - Forwarding and POP: "When messages are accessed with POP...".

Now for the mail delivery program Procmail:


Procmail is great sorting tool for use with any mail setup. It can be easily downloaded from the repository:

sudo apt-get install procmail

So where will Procmail deliver to? Traditionally all mail goes to the location specified in the $MAIL environment variable, but in a default Ubuntu system this is often not set. Set the MAIL variable by opening ~/.bashrc as follows:

vim ~/.bashrc

and adding the following, using your own username:

# Sets the Mail Environment Variable
MAIL=/var/spool/mail/john && export MAIL

A very simple configuration file must be created for procmail as follows:

vim ~/.procmailrc

and below is a very simple start to what can be quite a complex file:

# Environment variable assignments
VERBOSE=off                   # Turn on for verbose log
MAILDIR=$HOME/Mail            # Where Procmail recipes deliver
LOGFILE=$HOME/.procmaillog    # Keep a log for troubleshooting.
# Recipes
* ^TOmutt-user

I include a very simple sorting recipe with the file: this one intercepts everything addressed to "mutt-user" and directs it to $HOME/Mail/mutt. This is the mutt-user mailing list which I would advise all new mutt users to join. And lets not forget to create the Mail folder:

mkdir $HOME/Mail

Now finally to Mutt.

Install & Configure Mutt

Mutt is one of the truly great pieces of software under Linux. The following command downloads Mutt from the Ubuntu repository:

sudo apt-get install mutt

Mutt is driven by a configuration file that can be created as follows:

vim ~/.muttrc

I have spent some time building this file from scratch but for you, Gentle Reader, I include here a more basic version, similar to the one I started from:

# Boring details
set realname =john
set from =
set use_from = yes
set envelope_from ="yes"
set sendmail="/usr/bin/msmtp"

# If not set in environment variables:
set spoolfile = /var/spool/mail/john

# Folders
set folder="~/Mail"                # Mailboxes in here
set record="+sent"                 # where to store sent messages
set postponed="+postponed"         # where to store draft messages
set move=no                        # Don't move mail from the spool.

# Watch these mailboxes for new mail:
mailboxes ! +Fetchmail +slrn +mutt
set sort_browser=alpha    # Sort mailboxes by alpha(bet)

# Order of headers and what to show
hdr_order Date: From: User-Agent: X-Mailer \
          To: Cc: Reply-To: Subject:
ignore *
unignore Date: From: User-Agent: X-Mailer  \
         To: Cc: Reply-To: Subject:
# which editor do you want to use? 
# vim of course!
set editor="vim -c 'set tw=70 et' '+/^$' " 
set edit_headers          # See the headers when editing

# Aliases

set sort_alias=alias     # sort aliases in alpha order by alias name

# Odds and ends
set markers          # mark wrapped lines of text in the pager with a +
set smart_wrap       # Don't wrap mid-word
set pager_context=5  # Retain 5 lines of previous page when scrolling.
set status_on_top    # Status bar on top.
push <show-version>  # Shows mutt version at startup

Note: Procmail will create your mailbox in the spool, and set the appropriate permissions, when it first receives mail from fetchmail so don't worry that mutt cannot initially find this mailbox. If you wish to create the mailbox yourself the following permissions and ownership are required (taken from my own system):

-rw-rw---- 1 andrew mail 0 2008-10-23 10:12 /var/spool/mail/andrew

And finally it is reward time as you open Mutt, type ! to open a shell prompt, type fetchmail -v and start reading your mail! My parting gift is a little macro that was written for me by a generous person on the mutt-user mailing list that will actually do this for you when you simply press the key "I". Place the following in your ~/.muttrc file:

macro index,pager I '<shell-escape> fetchmail -v<enter>'

And welcome to the world of mutt!


MuttAndGmail (last edited 2014-02-27 07:10:50 by taurusone)