Exim Mail User Quota Messages

Pat_Coed

Verified User
Joined
Jan 20, 2013
Messages
27
Bit of an issue with Exim sending out warning messages for email accounts.

Basically, being ever conscious that wonderful customers will use their mailbox as a means of storing anything and everything and think nothing of their mailbox reaching several GB in size I'm implementing new rules and caps on mailbox sizes. (Obviously customers are being advised and updated, etc)

Putting the rules in place thanks to DA is a breeze and done within a few clicks.

The next step is making sure that customers are made aware that they are reaching their limit, and thereby given ample opportunity to take steps to manage their mailbox size like a grown up.

Again thanks to the code I found on DA website (http://help.directadmin.com/item.php?id=157) this was achieved in a few clicks.

As pointed out in another thread, this only warns once and if they hit the threshold again then the message won't be sent out. The quick and easy way I have found around that is to restart Exim AFTER they have reduced their mailbox size. This will then send another message out if/when they reach the 80% limit (or whatever you set it as) at which point you would need to reboot Exim. For me a temp fix is to make Exim restart once a week, maybe at say 4am on a Sunday morning or something. If anyone can suggest a better solution then this would be appreciated though.

Second question I now have, is how to get it to send the warning message to multiple emails i.e. [email protected] and also [email protected] - This will make me aware of it, and I can then chase/remind them manually too. (Tried user@domain (semi-colon ; ) [email protected] but that doesnt work)

Next question is can I, and if so how, use HTML and or special characters (% £ $ @ / \ etc etc etc) in the quota message sent out. Not looking at a huge message, but something less bland with a couple of links. Am I then better to manually insert this line by line into the exim.conf file (example as below) or should I just have a separate file and link it from my exim.conf file? Not sure how to do that, but may be a better idea? (As Im typing this, I've just discovered I can use the % symbol in the exim.conf quota message that is sent out. Did have issues using the / symbol though)

And my last question is can I configure it to send out several messages at say 80% then at 90% then at 95%? Assuming that if I copied the BOLD text below and repeated underneath but at 90% then at 95% then that would work? Not tried yet, just thinking out loud but again a robust solution would be apprecaited. :)


Rough mockup of the sort of thing I would like to send out.....

Code:
quota = ${if exists{/etc/virtual/${domain}/quota}{${lookup{$local_part}lsearch*{/etc/virtual/${domain}/quota}{$value}{0}}}{0}}
[B]quota_warn_threshold = 80%
quota_is_inclusive = false
quota_warn_message = "\
          To: $local_part@$domain\n\
          Subject: Your mailbox size is near its limit\n\n\
          This message was automatically created by the mail server.\n\n\
          The size of your mailbox for $local_part@$domain has reached 80% of your maximum mailbox size.\n\n\
          When you reach your mailbox limit, you will be unable to send or receive any emails until you reduce the size of your mailbox.\n\n\
          \n\n\
          \n\n\
          <u>Notes</u>
          You can reduce the size of your mailbox by either deleting large emails, deleting old and unnecessary emails or by emptying your Deleted Items/Trash/Messages folder\n\n\
          which will recover some of your space. For directions of how to do this, click <a href="http://www.mydomain.com/mailbox.pdf">HERE</a>\n"[/B]
 
I'm curious about this as well. When I originally looked into it months back, I had seen people on the exim mailing list saying it was possible but, of course, no examples of how to do it. As such, I've changed my approach to the situation and dovecot's quota plugin is what I'm looking into now. I don't know how well it will work alongside the exim quota warning (Probably disable it if this works as well as I hope it will) but at least it allows for more flexibility.

More info on that here:
http://wiki2.dovecot.org/Quota

The config page shows that there's far more flexibility allowed, with the different warning levels and being able to set up a script. As a result, you could e-mail users at lower quota levels and make it e-mail both them and you at higher levels.

I'm not sure how well this work in DA, not having implemented it myself yet, but someone else wrote up a guide containing it (http://forum.directadmin.com/showthread.php?t=33255) so it should be what we're both looking for.

Edit: Having trouble finding an easy way to obtain the e-mail tied to the account that the e-mail being warned belongs to. I can think of one way to do so but it's rather convoluted. Split the e-mail at the @, find which user that domain belongs to, and then search through either their ticket.conf or user.conf to grab it. There has to be something more elegant than that.
 
Last edited:
Thanks for that, will have a look and update. :)

On your last point, can't you just send it to the actual mailbox itself? Or are you looking to send it to a second (or administrative) contact aswell? Or have I got the wrong end of the stick.:confused:
 
The administrative contact/user account contact, yeah. More often than not, the owner of the e-mail won't pay enough attention to the warning e-mails so, at the very least, alerting the person in charge of the domain will let someone else know what's wrong.

I realized later that shell scripts can execute php scripts so you could just turn to those to manage everything, if need be. Still a bit messy but working with the API is more flexible.
 
Last edited:
Finally found some free time to explore the issue further. The guide I linked was designed with Dovecot 1.2 in mind and causes issues with the more recent versions of Dovecot. Following zEitEr's guide for setting up everything required for the quota system, this is what our dovecot.conf currently has:

Code:
plugin {
    sieve = ~/.dovecot.sieve
    sieve_global_path = /var/lib/dovecot/sieve/default.sieve
    sieve_dir = ~/sieve
    sieve_global_dir = /var/lib/dovecot/sieve/global/
    quota = maildir:User quota
    quota_rule = *:storage=50M
    quota_rule2 = Trash:storage=+25%%
    quota_warning = storage=95%% quota-warning 95 %u
    }
service quota-warning {
  executable = script /usr/local/bin/quota_warn.sh
  # use some unprivileged user for executing the quota warnings
  unix_listener quota-warning {
     user = dovecot
     mode = 0666
  }
  user = dovecot
}

The proper shell script is currently being worked on and that should hopefully be ready tomorrow. The quota_rules don't work yet unfortunately. Need to look into that further.

Edit: Still no luck on the quota_rules but the warning script works now. Had to change the user for the unix socket to root, which I'm not fond of, but the alternative was setting everything up in order to make an API call to fetch the contact e-mail associated with the account. I'll throw the script up on Monday once it is tidied up a bit.
 
Last edited:
Back
Top