Roland's homepage

My random knot in the Web

My e-mail setup

For years I’ve been using fetchmail and procmail for incoming mail. However, both of these programs haven’t been maintained for years. So it was time to change.

Problems

In 2018 I discovered that the latest fetchmail release from FreeBSD ports wouldn’t work with libressl. So I started building it myself from the gitlab repo.

Meanwhile, the latest procmail release was in 2001. Part of that is that the program seemed to be complete. However, over the years some bugs and vulnerabilities have popped up. For example in handling MIME headers. (See this lwn.net article for more info.)

So recently I decided it was time to renew and document my e-mail setup. My personal preference is to store my e-mail (especially my archives) on my own machines and backups rather than on an IMAP server somewhere. I hope this is a reasonable introduction for those with a UNIX-like workstations, or maybe even a raspberry pi used as a monitoring device.

Introduction

There are at least three paths for e-mail.

  • Local delivery (from programs)
  • Sending external mail
  • Retrieving mail from an external (POP3/IMAP) server.

The first two are commonly done by the same software.

Local delivery

For local delivery and sending e-mail in the dial-up days, I started with sendmail. Mainly because back in the day it was what was available. Even though it was way overkill for my use on a single UNIX-like workstation. And configuring it was an unpleasant experience, especially for someone not terribly familiar with e-mail. Around 2000 I switched to postfix, which was still overkill but significantly easier to configure.

Since 2015 I’ve used the much simpler DragonFly Mail Agent (dma), which is much more suited for single workstation use. This program itself needs no configuration for local delivery to work. But on FreeBSD you do need to configure mailwrapper(8) to use dma. This is done in /etc/mail/mailer.conf. For dma it should look like this:

sendmail    /usr/libexec/dma
send-mail   /usr/libexec/dma
mailq       /usr/libexec/dma

Local mail will be delivered in /var/mail/$USER. This is not configurable.

Note that on a UNIX machine status e-mails from daemons and system scripts might be sent to different users. The aliases file (usually /etc/aliases) is used to redirect mail from daemons and such to root. In there you should probably redirect mail for root to your normal user account so that it doesn’t pile up in the (unread) mailbox for root.

Sending external mail

This is also handled by dma. This does needs some configuration in /etc/dma/dma.conf. I have set the following options. See dma(8) for their meaning.

  • SMARTHOST
  • PORT
  • AUTHPATH
  • SECURETRANSFER
  • STARTTLS
  • MASQUERADE

For a single workstation you generally want to use a smarthost. For that to work you need to set up an authorization file auth.conf. Again, see dma(8).

Retrieving mail from an external server

The fdm program combines the jobs of fetching mail and filtering it. It replaces both fetchmail and procmail. I run the program from my crontab every 15 minutes, logging only errors:

*/15 * * * * fdm -q fetch >>${HOME}/fdm-errors.log 2>&1

Months go by without seeing an error, so that’s OK.

Configuring fdm is relatively simple. The fdm.conf(5) manual page is pretty clear, and there are some nice example in the source distribution.

My ~/.fdm.conf file is pretty simple. It starts with a couple of settings and a macro for the location of the mail folder:

set verify-certificates
set maximum-size 10M
# Macro holding the path where the mailboxes are.
$path = "%h/Mail"

For obvious reasons I’ll not show my mail account credentials. :-) See fdm.conf(5) for how to set up an account.

Mailboxes are defined with a subcommand of the action command:

action "inbox" mbox "${path}/received"
action "spam" mbox "${path}/spam"

These are basically the “must-have” mailboxes. Personally I like to separate mail from the government and associations that I belong to in their own mailboxes. This makes it easier to keep on top of things.

fdm can store mail in both mbox (all mails in one file) or maildir (every mail in its own file) format. For local storage I’ve always used mbox files without a problem in 20+ years.

After the mailboxes come rules in the form of match commands. Rules are tested sequentially until a match is found. This is used for determining to which action (mailbox) mail goes:

# Spam traps
match "To:.*undisclosed-recipients" in headers action "spam"
match not "To:.*rsmith" in headers action "spam"

It is important to have a last action that sends the remaining mail to your inbox:

# Default action.
match all action "inbox"

Spam filtering?

There have been years that I received 100+ spam messages a day. So I used to run bogofilter from procmail. After training I found it pretty accurate.

Luckily, spam levels have dropped so much that I could retire bogofilter in 2016. I have archived its data files though, just in case…


For comments, please send me an e-mail.


←  Nikon D70s tips and tricks Creating a screenshot in X11  →