Please note that this page is not necessarily a “how-to”, but more of an example of my configuration decisions. At the time of this writing, I am using Mutt 1.5.18 (2008-05-17), the mail/mutt-devel port in the FreeBSD ports tree.
Problem:
You want to use the mail client mutt to access your Gmail account.
Solution:
Mutt needs to be compiled with IMAP, SMTP and OpenSSL support for this to work. If you already have mutt installed, you can check the build flags with the following command:
mutt -v
If you do not see the options:
+USE_IMAP +USE_SMTP +USE_SSL_OPENSSL
you will need to recompile mutt.
Compiling Mutt with IMAP, SMTP, OpenSSL Support in FreeBSD:
In FreeBSD, to compile mutt with the required options:
cd /usr/ports/mail/mutt-devel
make -DWITH_MUTT_IMAP \
-DWITH_MUTT_IMAP_HEADER_CACHE \
-DWITH_MUTT_SMTP \
-DWITH_MUTT_CYRUS_SASL2
make install
Explanations:
- The
WITH_MUTT_IMAP option enables IMAP server connectivity — disabled by default.
- The
WITH_MUTT_IMAP_HEADER_CACHE option saves mail headers locally, enabling a quicker folder download time — especially useful if you use Gmail for mailing lists.
- The
WITH_MUTT_SMTP option is not required if you only plan to read email locally, or if you run a local mail server.
- The
WITH_MUTT_CYRUS_SASL2 option allows mutt to connect to the Gmail SMTP servers with TLS authentication — a requirement if you plan to send mail with mutt through Gmail.
Configuring Your ~/.muttrc:
As with all other mutt tricks, you need to edit your ~/.muttrc file to get IMAP/SMTP connectivity. My sample configuration is provided here:
set spoolfile = imaps://imap.gmail.com:993/INBOX # Default to the inbox
set folder = "imaps://imap.gmail.com:993/" # Connect to IMAP over SSL
set imap_user = 'my_username@gmail.com' # User name
set imap_pass = 'my_secret_password' # Password
set smtp_url="smtp://my_username@smtp.gmail.com:587/" # User name
set smtp_pass = 'my_secret_password' # Password
set postponed="imaps://imap.gmail.com/[Gmail]/Drafts" # Save 'postponed' mail to Drafts
set mail_check=300 # Check for new mail every 5 minutes
set imap_check_subscribed="yes" # Check 'subscribed' folders only
set imap_list_subscribed="yes" # List only 'subscribed' folders
set header_cache="~/.mutt/msgcache" # Location to save cached mail headers
set message_cachedir="~/.mutt/cache/bodies" # Location to save cached mail bodies
set certificate_file="~.mutt/certs" # SASL2 certificate location
set timeout=60 # Reconnect every minute
macro generic,index,pager y ? # Press 'y' to change folders
bind pager,browser y exit # Press 'y' to change folders
Some options in my sample ~/.muttrc file may seem a bit odd at first, but after reading the sections below, should become more clear. If not, please use the contact form, and let me know what was unclear, or how I could improve this tutorial.
Individual Preferences:
This is the part that gets a bit tricky. This is the part where you, the reader, are required to be creative. Here’s what I mean:
- Gmail sees “Labels” as folders
- Gmail uses its own “default” folder — [Gmail]
- Labels exist outside of the [Gmail] folder
So, logically, the hierarchy would look as such:
[Gmail]
/Inbox
/Sent Mail
/Drafts
Mutt-Users
Mutt-Devel
KDE-General
KDE-Devel
FreeBSD-Questions
FreeBSD-Stable
FreeBSD-Current
FreeBSD-PF
FreeBSD-Jails
School-Professors
School-Students
School-Clubs-CIS
Though this layout works perfectly fine, depending on how many labels you have, this can get a bit cumbersome, even with using header and body caching. The solution I found is to name labels in a Unix-like folder fashion. For instance, School-Clubs-CIS would the become School/Clubs/CIS, thus making the logical layout as any other Unix directory:
[Gmail]
/Inbox
/Sent Mail
/Drafts
Lists
/Mutt
/Users
/Devel
/KDE
/General
/Devel
/FreeBSD
/Questions
/Stable
/Current
/PF
/Jails
School
/Professors
/Students
/Clubs
/CIS
As I said, this is where you have to be creative. My solution here will not work for everyone, and I’m certain there are many naming conventions others will prefer.
By the way, this is where the ‘y’ in the ~/.muttrc file comes in — from the Inbox, pressing ‘y’ will take you to the folder list, where you can navigate through your folders.