Better Quota notifications for OSX Server

OSX Server comes pre-packaged with Dovecot one of the best IMAP services out there and one of the most extensible and flexible in my opinion. That is its flexible and extensible as long as you know how to configure Dovecot which most OSX Server Administrators are not. I had a conversation with a co-worker not too long ago about being an OSX Server Administrator and I joked that Apple made great hardware and a great OS but most if not all of the services under the hood for Web, Mail, Mailing Lists, etc… were all borrowed open source technologies and that Apple really does not offer any sort of support base for the open source technologies that they use. However without these pieces of software their entire PR Campaign would hold no water. What I praise Apple for is taking these tools and utilizing them and making them easier to use while leaving the ability to tinker and improve these services.

One such service is the topic today, Dovecot. Dovecot is integrated with Server Admin, Apples GUI Server Administration tool. You can set two different kind of notifications to trigger here, a quota notification that will send an email out when someone is over a certain percentage of email quota and an email warning them when they have gone over quota. In my experience it takes more than a couple emails to make a user clean up their inbox.

What I wanted was a way to say, send out an email when a user goes over a specified limit and then send an email every ten percent they go over the original limit. When they reach ten percent before their quota is exceeded increase the email notification rate to one email every percent until they reach their quota and then at that time continue to send an email a day until their quota has been reduced. On top of that I wanted it to also notify me of people who have gone over quota so that I can prove to them that they did indeed get the notification. For me a good solution was having all quota notifications CC’d to our help desk which in turn opened a ticket on the behalf of the offender in a sense sending them two emails each time they went over quota. I am going to cover the necessary steps needed to accomplish this task on your OSX Mail server.

** Note what we are about to do will mean that you will no longer be able to use Server Admin to manage email notifications.

1. Locate the Dovecot Configuration file.

cd /etc/dovecot/dovecot.conf

2. Edit the file

sudo pico /etc/dovecot/dovecot.conf

3. Find this line

quota_warning = storage=100%% /usr/libexec/dovecot/quota-exceeded.sh

we are going to modify this line and add the following lines.

quota_warning = storage=100%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning2 = storage=99%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning3 = storage=98%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning4 = storage=97%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning5 = storage=96%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning6 = storage=95%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning7 = storage=94%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning8 = storage=93%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning9 = storage=92%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning10 = storage=91%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning11 = storage=90%% /usr/libexec/dovecot/quota-exceeded.sh
  quota_warning12 = storage=87%% /usr/libexec/dovecot/quota-warning.sh
  quota_warning13 = storage=85%% /usr/libexec/dovecot/quota-warning.sh
  quota_warning14 = storage=80%% /usr/libexec/dovecot/quota-warning.sh
  quota_warning15 = storage=75%% /usr/libexec/dovecot/quota-warning.sh

What we are saying here is that we are going to send out an email every time someone is over their limit. Here the limit is 75% and every 5% they go over they will get another warning until they get to 90% then the warnings become more frequent one every 1%. Not only that but there are two different messages the quota-warning and the quota-exceeded.

4. We are going to create a new quota-warning.sh file

cd /usr/libexec/dovecot
sudo pico quota-warning.sh

This is the current default Apple script that triggers the default email created in Server Admin.

#!/bin/sh

_quota_txt=/etc/mail/quota_warning.txt

if [ -e $_quota_txt ]; then
  cat $_quota_txt | /usr/libexec/dovecot/deliver -d $USER
fi

We are going to modify this script to send out an email of our choice and to do so to another recipient so we have a record of users getting notifications.Here is the script that I wrote that does just that.

#!/bin/bash

PERCENT=$1
FROM_SMTP="support@somedomain.com"
FROM="FWW Support <support@somedomain.com>"
TO="FWW Support <mail-server-admini@somedomain.com>"
qwf="/tmp/quota.warning.$$"

echo "From: $FROM
To: $USER
Subject: Quota Notification
Content-Type: text/plain; charset="UTF-8"

Hello-
This is a warning email that was automatically sent. You are nearing your quota limit. The current quota is 1 GB of storage space per user. However you can store more offline.
Q: What can I do now?
A: Start backing up your emails and storing them in a folder under the On My Mac heading, this will ensure that your emails will still be stored and it will free up space on your online account.

If you need more assistance please contact Jon Brown at 
support@somedomain.com.
Thank you for your cooperation!
-- Some Organization Mail Server" > $qwf

cat $qwf | /usr/sbin/sendmail -f $FROM_SMTP "$USER"
rm -f $qwf

echo "From: $USER
To: support@somedomain.com
Subject: Quota Notification
Content-Type: text/plain; charset="UTF-8"

Hello  -

$USER Is nearing their quota. Please follow these steps.
1. Call the user and make sure they understand how to archive their email.
2. Explain to the user that they can sort their email by largest size, tell them to discard or remove the largest emails first.
3. Ensure that the quota has been reduced in Server Admin, do not increase the quota unless it is an emergency.
-- Some Organization Mail Server" > $qwf

cat $qwf | /usr/sbin/sendmail -f $FROM_SMTP "support@somedomain.com"
rm -f $qwf
exit 0

You must replace the above script with the old script entirely. This will negate the ability to use the text file that Server Admin uses for email notifications but allows you to send the notification to multiple people.

4. We are going to create a new quota-exceeded.sh file

cd /usr/libexec/dovecot
sudo pico quota-warning.sh

This is the current default Apple script that triggers the default email created in Server Admin.

#!/bin/sh
_quota_txt=/etc/mail/quota_exceeded.txt
if [ -e $_quota_txt ]; then
  cat $_quota_txt | /usr/libexec/dovecot/deliver -d $USER
fi

We are going to re-write this script and use the following to do similar to the above but at a more aggressive rate.

#!/bin/bash
PERCENT=$1
FROM_SMTP="support@somedomain.com"
FROM="FWW Support <support@somedomain.com>"
TO="FWW Support <mail-server-admin@somedomain.com>"
qwf="/tmp/quota.warning.$$"
echo "From: $FROM
To: $USER
Subject: FWW ***You're Over Your Quota***
Content-Type: text/plain; charset="UTF-8"
Hello-
This is a warning email that was automatically sent. You are nearing your quota limit. The current quota is 1 GB of storage space per user. However you can store more offline.
Q: What can I do now?
A: Start backing up your emails and storing them in a folder under the On My Mac heading, this will ensure that your emails will still be stored and it will free up space on your online account.
If you need more assistance please contact Jon Brown at support@somedomain.com.
Thank you for your cooperation!
-- Mac Server" > $qwf

cat $qwf | /usr/sbin/sendmail -f $FROM_SMTP "$USER"
rm -f $qwf

echo "From: $USER
To: support@somedomain.com
Subject: FWW ***You're Over Your Quota***
Content-Type: text/plain; charset="UTF-8"

Hello  -
$USER Is nearing their quota. Please follow these steps.
1. Call the user and make sure they understand how to archive their email.
2. Explain to the user that they can sort their email by largest size, tell them to discard or remove the largest emails first.
3. Ensure that the quota has been reduced in Server Admin, do not increase the quota unless it is an emergency.
4. Explain to the user that their email will stop working if they reach 99% capacity.
-- Mac Server" > $qwf
cat $qwf | /usr/sbin/sendmail -f $FROM_SMTP "support@somedomain.com"
rm -f $qwf
exit 0

That is it, once you are done you must restart dovecot.

sudo serveradmin stop mail
sudo serveradmin start mail

Once done you will now be able to enjoy the fruits of your labor. Your users will now get a lot more notifications which will mean that they will be more likely to tame their unruly inboxes on their own and you will be notified as to when they are getting notifications so that you can better assist them with this task. As always I encourage your comments, suggestions and questions. I hope you all enjoyed my post and thanks for reading!

AI Usage Transparency Report

Pre-AI Era · Written before widespread use of generative AI tools

AI Signal Composition

Rep Tone Struct List Instr
Repetition: 65%
Tone: 52%
Structure: 59%
List: 6%
Instructional: 50%
Emoji: 0%

Score: 0.07 · Low AI Influence

Summary

A detailed guide on configuring Dovecot IMAP service on OSX Server, including customizing quota notifications and creating new scripts for email sending.

Related Posts

10.6.8 Server high CPU usage, hwmond culprit

It seems no matter how careful Apple is each OS update (especially server updates) reveals its own challenges for the user, that leaves them wishing that they had not left their stable platform for the bug fixes that made that update so desirable. The 10.6.8 server update was no different; it claimed to fix such long-time bugs as Server Side Rules, which has been a thorn in the side of OS X Server Administrators everywhere who use OS X Servers as their primary email server. So many of us, including...

Read more

OSX Server Mailman Tricks

We have been using XServes as our primary mail servers at my organization for about two years now; we upgraded from an older Linux system and we could not be happier, since moving over to the 10.6 platform, we have enjoyed almost no email downtime, very easy to manage mail system and of course all the goodies that you would expect to run, some of which I have already mentioned (Squirrelmail) and also Mailman. Through my time configuring the server, migrating data and through other requests I have compiled a...

Read more

10.6.2 Mail Server draws a blank, subject?

So we upgraded from 10.5.8 Mail server to 10.6.2 and everything went very smoothly. Mailstores were migrated and the transition from Cyrus to Dovecot was great. However once all the email was moved over and all the settings were double, and triple checked. People started complaining that every once in a while their email was not getting through the server, it was getting bounced back to the sender. At first I thought that it was an internal issue with the users on our network, then I got a complaint from...

Read more

10.6.2 Dovecot Mail Backups

Before migrating to 10.6 Server we were running our entire mailstore on the 10.5.8 platform. Say what you will about Leopard, once we had it set up correctly it ran fine. We migrated because of the greater benefits of Dovecot over Cyrus. Many of the other features intriqued us as well such as the improved Wiki server and iCal server. However we were really excited about Dovecots ability to repair itself basically doing away with the need to ever have to rebuild a users mailbox.

Read more

10.6.2 Squirrelmail, LDAP & Sieve

Snow Leopard 10.6 comes with built in Server Side rules (Sieve) that helps you to organize mail, if your like me and am supremely disappointed at the lack of functionality then you will be happy to know that there are alternatives out there. Snow Leopard still ships with a copy of Squirrel mail for OSX it also ships with many cool plugins for squirrel mail already installed. Lets look at the alternative to the built in Sieve scripts that ship with 10.6 Snow Leopard server.

Read more

10.6.2 Roundcube & LDAP

So like many other organizations mine was finally fed up with Horde as a webmail system. They had used squirrel mail in the past and was unimpressed by the graphical interface but admitted that it while it lacked glamour it always did perform as they would have expected. Before I had started there their mail system was running on a Linux box using Plesk and running Horde as their primary webmail interface. Immediately I got them into an XServe running OSX mail since their entire organization consisted of Apple iMacs...

Read more

10.5.8 Server Upgrade : Mail

Recently I have undergone a massive change, we have decided at our organization to go with Snow Leopard server in place of our Leopard Servers. Knowing that this could be problematic to use Apples built in GUI for migrating data I decided to start with a 100% clean configured Snow Leopard server and slowly start to migrate items over to the new server. Our current Leopard Server was running an DNS, Open Directory Master, Mail, and Wiki Server services. I have decided to share my experience in migrating our mail...

Read more

Roll your own DNS monitoring with DIG, Bash & CRON

If your like me your always looking for ways to be notified of things changing in your IT Environment. There are many tools that you can use to help do this. StatusCake is a great free online tool for monitoring website and IP level uptime and downtime with baked in email notifications. Zeonoss and NAGIOS are great tools that can offer the same with SNMP Monitoring baked in as well.

Read more

Authenticate with AD credentials via ARD / SSH

Binding a Mac to an AD is fairly straight forward. Most Mac Admin's worth their salt, know how this is done, many know how to do this via the command line. Once your Mac is bound, authentication is easy, local authentication that is. But what if you want to use your secure AD credentials over an SSH or Apple Remote Desktop connection? Well thats when things need a bit more configuration. Having recently deployed a series of servers with this configuration I figured I would share some of the commands...

Read more