Mail handling with getmail, procmail, mutt and exim4

27.07.2005 at 22:17

I recently needed to reinstall my mailing tools and so i am going to write about it in this blogentry. I have used getmail to fetch the mails from the POP3 Server, procmail to filter them, mutt to display them and finally exim4 to forward new mails to my providers server for delivering.

Installing the nescessary packages

apt-get update && apt-get install getmail procmail mutt exim4

Getting the mails from the server

Depending on your needs there are different solutions, the simplest is to just grab the mails from your providers POP3-server without further processing such as filtering them into different mail boxes etc. This can be achieved by adding 2 lines to your ~/.muttrc file:

set pop_host=""
set pop_user=""

You can test your settings by starting mutt and then pressing G (Shift + g) mutt should now try to download your mails.

However this is not so comfortable if you want to categorize your mails into different mailboxes. For example a mailbox for each subscribed mailing-list. In this case i would recommend a seperate tool such as fetchmail or getmail for downloading the mails. I personally use the latter, because it is quite simple and still provides all the features that i currently need. Now we have to configure it so that it can download the mails and forward them to procmail which will categorize them. This configuration is only valid for version 4.x of getmail.

mkdir ~/.getmail/ && cd ~/.getmail/
cat > getmailrc << "EOF"
# print out some information
verbose = 1
# just read new mails
read_all = false
# don't delete the mails on the server
delete = false
message_log = /home/username/.getmail/log

type = SimplePOP3Retriever
server =
username =
password = yourgmailpassword

type = MDA_external
path = /usr/bin/procmail
# procmail requires either that the message starts with an mboxrd-style
# "From " line (which getmail can generate by setting "unixfrom" to True), or
# that the -f option is provided as below.
arguments = ("-f", "%(sender)", "-m", "/home/username/.procmailrc")

Sorting them with prcomail

Next we have to set up procmail, note this is just a minimal configuration refer to the procmail manual for further information.

cat > ~/.procmailrc << "EOF"

# example of filtering for mailing lists
# all mails to debian-user will be send to
# the debian-user directory.
* ^TO_debian-user

# all other mails will be moved to the inbox

Create the mailboxes.

mkdir -p ~/mail/inbox/{cur,new,tmp}
mkdir -p ~/mail/sent/{cur,new,tmp}
mkdir -p ~/mail/yourmailbox/{cur,new,tmp}

You can test the settings by running getmail, if it succeeds then you should have some mails in ~/mail/inbox.

Setting up exim4 for SMTP Authentication with the ISP

So far we are able to fetch and read our mails but not yet to send new ones. To change this we have to configure exim4 in "mail sent by smarthost; recieved via SMTP or Fetchmail" mode. This and some other options can be configured with dpkg-reconfigure.

dpkg-reconfigure -phigh exim4-config

Additionally we have to provide our accountname and password which exim will use for SMTP Authentication with the mail server of our ISP. This information is stored in /etc/exim4/passwd.client.

echo "$accountname:$accountpassword" >> /etc/exim4/passwd.client

Try to send a testmail it should now deliver correctly.

Mutt configuration

As a final step we can tweak our mutt configuration a bit, here are the important settings from my file for further options see the mutt documentation.

set mbox_type=maildir
set mbox="~/mail/inbox/"
set spoolfile="~/mail/inbox/"
set folder="~/mail/"
set record="~/mail/sent/"

mailboxes ~/mail/inbox ~/mail/debian-user
set sort=threads
set include=yes
set indent_str="> "

subscribe debian-user

Now you can (hopefully) read your mails and enjoy.

mutt                         # opens standard mailbox ~/mail/inbox
mutt -f ~/mail/custommailbox # opens custommailbox

Setting up a crontab

Ok one last thing, if your to lazy to run getmail by hand then set up a crontab. In the following example getmail gets executed every 10 minutes.

crontab -e
*/10 * * * * getmail

Comments (0)

There are currently no comments available