So, I have finally configured “mutt“, the terminal based email client on my Slackware 13.1. I have been thinking of doing this since ages (same with other things, pending since ages). Its a cool, nice, easy to use client with main focus (at least mine) on not moving your hands away from keyboard to check/send emails.
As Slackware doesn’t come pre-installed with postfix and the default email server is Sendmail here, I thought it would be easier to configure sendmail than to configure/compile postfix. It took me a lot of time to customise the client to suit my needs and getting everything to work accordingly, but in the end I think its worth it.
There are nice tutorials on the web on installing mutt with sendmail/postfix/fetchmail with some default configuration examples also. Postfix users can use this tutorial here which I also followed initially.
First of all, the tools needed, though most of these utilities come by default for most distributions.:
- fetchmail: to fetch the email from the email server (gmail etc.)
- procmail: responsible for delivering email to the local mail folders.
- sendmail: mail server used for sending the emails.
- mutt: the email client.
First of all, we need to download the gmail certificates as we will be using TLS for the encrypted session. Do this ont eh command line to fetch the pop certificate chain:
$ openssl s_client -connect pop.gmail.com:995 -showcerts
You will receive 2 certificates, first issued for the Google Internet Authority and the second, the issuer authority: Equifax Secure Certificate Authority. Copy the certificates (start from —–BEGIN CERTIFICATE till —–END CERTIFICATE—-) into 2 different files, save the first one as ~/.mutt/certs/google.pem and the second one as ~/.mutt/certs/Equifax_Secure_CA.pem.
Though the authority certificates (also known as root certificates) are installed by default on most distros, I just keep everything inside my $HOME independently, in case I switch my OS (which I often do).
Now run $ c_rehash ~/.mutt/certs/ which will create symlinks of the certificates in that directory.
We can now proceed to configuring fetchmail. Open your favourite editor and create a file called “.fetchmailrc” inside your $HOME. Here are the contents of this file:
set daemon 60
set postmaster ‘USER’
poll pop.gmail.com with proto pop3
user “firstname.lastname@example.org” is ‘USER’ here
options ssl sslcertck sslcertpath ‘.mutt/certs’ keep
with mda “procmail -d %T”
# For debugging, use
# fetchmail -Nvvvd0 –nosyslog
Replace USER with your local UNIX login name and username with the gmail username. You may or may not write your password inside the file for security purposes, comment it out with a # if you don’t want to use it. You can change the daemon time on the first line to make it fetch your mails every <n> seconds.
You can check the above configuration by running fetchmail from the command line, and see if you are receiving your emails: $ fetchmail -Nvvvd0 –nosyslog. If everything works out fine, you may want to start fetchmail at start-up using rc.local or something, but make sure you have the password inside fetchmailrc for that to work, otherwise boot up loading will stop to ask you the password.
Next, we configure sendmail for sending our emails. Slackware (or probably every distro) has some prebuilt sendmail configuration files in the /usr/share directory for TLS and SASL. You can modify that file and copy it as /etc/mail/sendmail.cf. Another option is to modify the .mc files and then creating a fresh .cf file from that, which is what I did.
Open up /usr/share/sendmail/cf/cf/sendmail-slackware-tls-sasl.mc and modify these things:
- Change dnl define(`SMART_HOST’,`mailserver.example.com’) to define(`SMART_HOST’,`smtp.gmail.com’)
- Add these:
- define(`RELAY_MAILER_ARGS’, `TCP $h 587′)
- define(`ESMTP_MAILER_ARGS’, `TCP $h 587′)
- FEATURE(`authinfo’,`hash /etc/mail/auth/client-info’)dnl
- Change DAEMON_OPTIONS(`Port=smtps, Name=MSA-SSL, M=Esa’)dnl to DAEMON_OPTIONS(`Port=smtps,Name=MSA-SSL, M=Ea’)dnl
Now you can run the Batch script to generate your own .cf file according to the instructions inside the mc file and use it as your sendmail.cf. Now, copy and paste this Thawte certificate inside your certs directory as Thawte_Premium_Server_CA.pem:
Changes you need to do inside the cf file:
- O CACertPath=~/.mutt/certs/
- O CACertFile=~/.mutt/certs/Thawte_Premium_Server_CA.pem
- Kauthinfo hash /etc/mail/auth/client-info
You need to create an ‘auth’ directory inside /etc/mail and chmod it 700. Create a file called client-info (with chmod 600) inside that with this structure:
AuthInfo:smtp.gmail.com “U:smmsp” “I:email@example.com” “P:xxxxx” “M:PLAIN”
AuthInfo:smtp.gmail.com:587 “U:smmsp” “I:firstname.lastname@example.org” “P:xxxxxx” “M:PLAIN”
Replace username with your gmail username and xxxxxx with your password. Now, run $ makemap -r hash /etc/mail/auth/client-info.db < /etc/mail/auth/client-info which will create a hash of your login credentials.
Optional procmail configuration which is not needed for most users, but if you are a control freak, create one .procmailrc inside $HOME:
MAILDIR=$HOME/Mail # all mailboxes are in Mail/
Replace USER with your username. This will set the default mail spool mbox as ~/Mail/USER and not /var/spool/mail/USER. Though this method has a disadvantage of not getting notified of new mails when there is a key-stroke on the terminal. I am yet to figure on how to change that.
Lets move on the final step, which is mutt configuration. I must say that mutt is lightweight but still quite powerful. You can do almost everything with it which you can do with some GUI based mail client. Create a file called ~/.mutt/muttrc with these important commands/options:
- alias name First-Name Last-Name <email@example.com>
- set alternates=’firstname.lastname@example.org’
- set alternates=”*@localhost”
- set folder=”~/Mail”
- set mbox_type=”Maildir”
- set postponed=”~/Mail/drafts”
- source “~/.mutt/mail-aliases”
- set alias_file=”~/.mutt/mail-aliases”
- set from=”email@example.com”
- set mail_check=60
- set mailcap_path=”~/.mailcap” # (copy it from /etc)
- set record=”~/Mail/sent”
Most of the times, you woudn’t want to change the other default configuration but if you want more customisation, here are a few options which I found useful:
- set spoolfile=”~/Mail/chiky” # As I said, I like to keep everything inside my $HOME. For this to work, you should have the above procmail configuration.
- # Removing unnecessary headers
- hdr_order Date From To Subject
- set askcc=”yes”
- set sendmail_wait=-1 # forks sendmail in the background
- set sort=”reverse-threads”
- set sort_aux=”date”
- For various mailboxes, see this: http://wiki.mutt.org/?MuttFaq/Maildir
A few color options which I like (thanks to openSUSE default config):
color hdrdefault red default
color quoted brightblue default
color signature red default
color indicator brightyellow red
color error brightred default
color status yellow default
color tree magenta default # the thread tree in the index menu
color tilde magenta default
color message brightcyan default
color markers brightcyan default
color attachment brightmagenta default
color search default green # how to highlight search patterns in the pager
color header brightred default “^(From|Subject|Date|To):”
color body magenta default “(ftp|http|https)://[^ ]+” # point out URLs
color body magenta default “[-a-z_0-9.]+@[-a-z_0-9.]+” # e-mail addresses
color underline brightgreen default
Then you can obviously any time go through ‘man muttrc’ for all the other cool options and change them according to your taste.
Now, open mutt inside your terminal, and see if everything is working. If not, do comment here.
Thanks to http://www.mayin.org/geta/gmail-postfix-fetchmail-setup.html for the initial tutorial.
- No public Twitter messages.