The almost forgotten art of procmail with fetchmail
Last edited: $Date: 2015/11/17 10:58:53 $
A friend has setup a POP3 server for one of my domains. So this was
a nice trigger to start remembering how I used to use POP for email.
On my diskless OpenBSD 5.7 machine I installed fetchmail, procmail
and mutt and started playing with it.
I simply installed fetchmail, procmail and mutt with the `pkg_add`
> Fetching and processing mail just like in the old days
Procmail is a very powerful tool that kind do all kind of email
magic. We will only touch the surface here.
## Using fetchmail to retrieve email
The first thing I do is fetch my email, deleting it on the POP3
The most simple way to use fetchmail is to setup a .fetchmailrc file
in your $HOME directory and run fetchmail.
The .fetchmailrc contains something like this:
set postmaster "matto"
set logfile /home/matto/.fetchmail.log
poll pop3.example.com protocol pop3:
username "" password "";
mda "/usr/local/bin/procmail -d %T"
The first line is to make sure all mail comes to my user, which is
"matto". The second line is to keep a log.
The third line contains the name of the POP3 server. The foutth line
contains the username ans password for the POP3 server.
The last line tells fetchmail to forward all incoming mail to
procmail. The path depends on the system you have, on OpenBSD is it
## Using procmail to filter your email
Next, setup a .forward file in your $HOME directory:
All this .forward file does is telling that mail should be processed
by procmail. Again, check the path.
Now the magic begins.
Create a .procmailrc file in your $HOME directory:
This .procmailrc file contains a block with some settings followed
by two procmail recipes.
This .procmailrc file does several things.
* It tells procmail which shell and which path-settings to use
* It tells procmail that my mailboxes line in the $HOME/Mail directory
* It tell procmail to use the default mailbox "junk" to deliver the
* It tells procmail to use the mailbox "spam" to deliver all mail in
with in the subjectline the word "SPAM"
* It tells procmail to use the mailbox "inbox" to deliver all mail
that is sent to firstname.lastname@example.org
Spammers use all kind of usernames before the @example.com, this way
they all end up in the "junk" mailbox, except the ones addressed
directly to me (here: email@example.com).
After running this for a few days, you add a spam recipe with
something like this:
* ^X-Spam-Status: Yes
This will send all email that has a line which starts with "X-Spam-
Status: Yes" to /dev/null, which is a geeky way of telling to
If you are following mailing-lists, it might be a good idea to add a
filter for those lists. Example:
All mail sent to this list will be collected in the mailbox "linux".
Now you can tell Mutt to use its powerful mailinglist-features on
You can add as many as procmail-recipes as you want. They can be
## Use Mutt to read and write email
> Mutt is the most powerful email client
Add some lines to your .muttrc to let Mutt knows where your
set spoolfile = "$HOME/Mail/inbox"
set folder="$HOME/Mail" # Local mailboxes stored here
set mbox_type=mbox # Mailbox type
The default keybinding to change to a different mailbox in Mutt is
'c', so this is how you can go from the inbox to the other
Here are some nice reads that helped me setup my procmail/fetchmail
$Id: fetchmail.txt,v 1.4 2015/11/17 10:58:53 matto Exp $