Raspberry Pi Exim4 config for local hMailServer smtp, and low disk space alert

My existing Raspberry Pi OpenVPN solution needed “fixing” but when I came to do it I discovered I’d run-out of space on the 8GB microSD card.

It took a while to track down the culprit … a log file in the hidden .cache directory in my home directory – over 2GB in size. Plus this Pi, although dedicated now to OpenVPN, has all the bells and whistle uselessly installed on it. Ideally I need to start afresh some time with a minimum install. I wish I kept notes on finding that file as I learned new stuff along the way but alas I was too frustrated to do so at the time.

Instead I’m setting-up a low disk space alert to be emailed to me. I’m still a noob in Linux (a “tourist” as I put it) and have only had a little experience with email, so far with sendmail in Ubuntu. It so happened that most of the material I was reading for the topics I was interested in, all seemed to talk about Exim4 on the Pi and made me erroneously believe I should go in that direction. Over the top for my needs – and I’ve since discovered that sendmail should work fine on the Pi, and ssmpt and so on. As I already have a perfectly good SMTP server sitting on my network – that’s what I want to use!

To me, hMailServer in Windows is brilliant. It’s easy to use, intuitive, and plenty powerful enough for just a few concurrent IMAP users and a few domains / tens of accounts. It’s easy to set-up relays with it and to back it up and migrate it. Easy to set-up anti-spam, anti-virus, security, protocols, TLS and SSL certificates. It’s easy! A lot easier than Exchange set-ups. And a lot lot easier than Linux-based set-ups if equivalency in control and power is desirable. I’ve had it running in a Windows 8.1 VM for many years together with an IIS webserver for various experiments and WordPress sites. Now though I want to migrate it to a Compute Stick dedicated to email, possibly with it’s own 3G back-up (though might rely on that in PF Sense). I’m changing a lot of stuff in my network around and I’ve learned from years of experience what I can trust and how to better make use of resources. Obviously I want to use hMailServer as my internal SMTP Server … that any device on my network is welcome to use to send me email. I thought it was a simple enough premise.

Well, it is, but initially I was confused. I persevered however and am recording my set-up here.

I already have DDNS set-up with a CNAME vpn.xarta.co.uk that resolves to my dynamic IP so that’s a nice valid address I can use as a FQDN. (This is for the Raspberry Pi dedicated to the singular purpose of providing an OpenVPN server).

Still not sure if I need to add anything else to this bit yet:

I have different SMTP ports set-up, one with optional STARTTLS for example and another with required TLS … but I’m not sure how Exim4 works yet in this regard. I’d certainly prefer to encrypt all internal communications if possible. But I don’t want to use authentication – my hMailServer is set to permit any (non-spam) to be sent to local domains without authentication.

Hmmm … seem to be missing a step. Maybe one step doesn’t repeat on re-runs. Regarding entering recipients such that at least one is local to the machine sending the email – to read on that system. Didn’t make sense to me so I just entered my email address as hosted on hMailServer in there. So far so good, with basic tests.

Checking my aliases just to be sure of what’s what:

Finally I installed Logwatch, set its config for mail and html, and gave it a manual go:

Now at least I can keep an eye on disk usage. Eventually, of course, my MQTT cross-platform .NET Core client will be able to talk to my own instrumentation for real-time monitoring and alerts, but this will do for now.

Later …

And there’s always a “later”, I realised that missing step I couldn’t screen capture because it didn’t appear again, for configuring Exim4, was important. I’d ****-it-up of course. Although I could send mail to root@localhost, despite those aliases, I couldn’t send mail to root. I needed to update

pi@raspVPN:/ $ sudo nano /etc/email-addresses

Just as a note to myself … if I need to update the initial configuration:

Below script from: https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html … which I could then schedule with crontab -e

Edited for Bash rather than sh

# set -x
# Shell script to monitor or watch the disk space
# https://www.cyberciti.biz/tips/shell-script-to-watch-the-disk-space.html
# It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%.
# --------------------------------------------------------------------------
# Set admin email so that you can get email
# set alert level 90% is default
# Exclude list of unwanted monitoring, if several partitions then use "|" to separate the partitions.
# An example: EXCLUDE_LIST="/dev/hdd1|/dev/hdc5"
function main_prog() {
while read output;
echo $output
 #TODO if running out of space, look for big files > 100M and also pipe to mail
 usep=$(echo $output | awk '{print $1}' | cut -d'%' -f1)
 partition=$(echo $output | awk '{print $2}')
 #echo $usep
 if [ $usep -ge $ALERT ]
    #echo "true"
    echo "Running out of space \"$partition ($usep%)\" on server $(hostname), $(date)" | \
    mail -s "Alert: Almost out of disk space $usep%" $ADMIN

if [ "$EXCLUDE_LIST" != "" ]
  df -H | grep -vE "^Filesystem|tmpfs|cdrom|${EXCLUDE_LIST}" | awk '{print $5 " " $6}' | main_prog
  df -H | grep -vE "^Filesystem|tmpfs|cdrom" | awk '{print $5 " " $6}' | main_prog


Test, running lowdiskspace.sh under my Pi account (with ALERT set to 50):

Think I’m ok running this script as Pi though not 100% in case df needs elevated permission for some situations.