*** This thread has been locked at the poster's request. The new version of this howto may be found here ***
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. Despite the thread title, which speaks of Gutsy Gibbon, this guide should work under most versions of Ubuntu. I am using it myself under Intrepid Ibex with no problems.
There are a few steps involved but if followed carefully and in sequence you will soon be using Mutt successfully with your Gmail account.
In sequence we will:
- Set up an SSL and some certificates
- Set up the Mail Transport Agent msmtp
- Set up the Mail Transport Agent Fetchmail
- Set up the Mail Delivery Agent Procmail
- Set up our mail program Mutt
Sections that require your details inserted are in bold and red to eliminate some confusion . Lets get started with SSL:
Gmail uses the POP3-over-SSL protocol to protect the transmission of username and password over the Internet. You will need to install open ssl and a certificate pack:
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: ssmtp.
$ sudo apt-get install openssl ca-certificates
msmtp is a great and wonderfully reliable way to move mail from your computer. Download it from the repository as follows:
There is a single configuration file to be altered: $HOME/.msmtprc. It can be created and permissions set as follows:
$ sudo apt-get install msmtp
Below is the required configuration for a Gmail server:
$ touch $HOME/.msmtprc
$ touch $HOME/.msmtp.log
$ chmod 0600 $HOME/.msmtprc
Now to the MTA Fetchmail:
Next to download fetchmail from the Ubuntu repository:
Once again a single configuration file is required and so you will need to create ~/.fetchmailrc as follows:
$ sudo apt-get install fetchmail
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:
$ vim ~/.fetchmailrc
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:
poll pop.gmail.com # Tell fetchmail about server
with proto POP3 # Use the POP-protocol
user 'Gmail Username ' # Your Gmail Username
there with password 'Gmail Password' # Your Gmail Password
is 'username' here # Local Username
mda "/usr/bin/procmail -d %T" # Tell fetchmail which MDA to use
options # Options duh
keep # Keep the mail on server = safe
ssl # Use ssl
sslcertck # Check the certificates
sslcertpath /etc/ssl/certs # Path to the certificates
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...".
$ chmod 600 ~/.fetchmailrc
Now for the mail delivery program Procmail:
Procmail can be easily downloaded from the repository:
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:
$ sudo apt-get install procmail
and adding the following, using your own username:
A very simple configuration file must be created for procmail as follows:
# Sets the Mail Environment Variable
MAIL=/var/spool/mail/username && export MAIL
and below is a very simple start to what can be quite a complex file:
$ vim ~/.procmailrc
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:
# 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.
Now finally to the MUA: Mutt.
The following command downloads mutt from the Ubuntu repository:
Mutt is driven by a configuration file that can be created as follows:
$ sudo apt-get install mutt
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:
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):
# Boring details
set realname = "Your realname"
set from = "Email address"
set use_from = yes
set envelope_from ="yes"
# If not set in environment variables:
set spoolfile = /var/spool/mail/user-name
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:
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
set sort_alias=alias # sort aliases in alpha order by alias name
# Colours: This scheme is fairly basic and only
# really works if your Terminal background is white
color hdrdefault black default
color quoted red default
color signature brightblack default
color indicator brightwhite red
color attachment black green
color error red default
color message blue default
color search brightwhite magenta
color status brightyellow blue
color tree red default
color normal blue default
color tilde green default
color bold brightyellow default
color markers red default
# 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
-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:
And welcome to the world of mutt!
macro index,pager I '<shell-escape> fetchmail -v<enter>'
October 23rd, 2008