DescriptionThis scripts will send a message to a user when his mailbox size gets within a specified percentage of his max mailbox size. Originally posted in this thread.

Requirements hMailServer 4 or greater.

UsageCopy this code to your eventhandler.vbs. If you already have code in your OnDeliverMessage subroutine, then you will have to merge the contents of the OnDeliverMessage subroutine below with your own. Configure the variables in the user defined constant block to reflect your server environment and needs.

'*************************************************************** 'DisposeVariables: Clean up any variables we might have been using ' '*************************************************************** Sub DisposeVariables DebugLog.Dispose Set DebugLog = Nothing End Sub

One good thing with this section of the forum is that I get a better view of what changes are needed in the COM API. I've added three small COM API feature-requests that would make this specific script shorter and faster. Probably took me longer time to enter than then to implement them but I use the "Feature requests"-section as a todolist..

Thanks. I don't actually use it either as none of my users have quotas. I wrote it along with a few others based on posts/feature requests in order to get a feel for what you could do with the scripting. The COM API improvements you proposed would definitely make the scripting easier.

One thing from the script I would like to see added are Initialize and Deinitialize event handlers (Load/Unload, or whatever, it doesn't really matter what they are called). You'd be assured of the initialize being called before any other event and the deinitialize being called before the script is unloaded from memory. It would be nice if it was only fired once when the script was loaded into memory (and not every time an event fired), but the other way would work too.

I haven't actually tested to see if global variable values are retained between events, but I'd like to see that too as it let you keep in-memory lists of things (like received mail perhaps or a dynamic blacklist or make a logger that does bulk disk writes as opposed to line by line writes).

> I haven't actually tested to see if global variable values are retained between events,

They aren't. But I agree that it ofcourse would be good if they were. But today, every VBA script is executed as an independent unit.

The reason for this is threading problems which makes it a bit hard to implement properly (if it's even possible..). And even if I implement it properly in the server, I'm a bit scared that it will cause confusion for people that write script and doesn't know how multithreading affect their scripts.

I have a guess that you already know about threading problems (actually I'm almost sure..), otherwise, here's a short explanation.

Say for example that you have a small script that updates the global variable gNoOfDelivMsg (number of delivered messages) in the OnDeliverMessage event. The update is done using the following code:

Now say that the current value of gNoOfDelivMsg is 100. If two delivery threads executes line 2 the same time, they will both set iNewCount to 101. And then they will both set gNoOfDelivMsg to 101, even though there's actually two messages that has been delivered. So the value of the variable gNoOfDelivMsg will become incorrect.

Even if you rewrite the code to gNoOfDelivMsg = gNoOfDelivMsg +1 it won't work. This single line of code is expanded to several lines (when the VBA code is converted to processor instructions).

One alternative would be to have a shared "VBA environment", but that hMailServer only allows one script to run at a time. So if 5 events should be executed, they would just have to queue up. But this would give bad performance since (as example) hMailServer wouldn't be able to run OnAcceptMessage because OnDeliverMessage is running a large virus scan.

I'm simply not aware of a good workaround to this problem. It would ofcourse be better if all VBA-scripts could be executed in the same "memory area" (or whatever it's called). Perhaps you have a suggestion?

Well, any solution definitely adds complexity, but one place to look for a solution is ASP. ASP has an Application object which is essentially a dictionary/hashtable object that allows you to store data in it which is accessible from any ASP thread that is executing within the same application (web site). The Application object has a locking mechanism so you can do:

wiht the code you provided above, how many e-mails does it send out to a user?

i checked one of mine and it sent out 3 emails. I have the settings to show the warning at 0.05. I checked the emails that i have received and the size is not even close to 5% left of the quota. (for eg. 29 mb size, and 50 mb quota).

Is it possible to send out one e-mail a week or something? Instead of multiple e-mails. Thanks.

It's a bit late, but I figured a slow response is better than no response...

nwkit wrote:wiht the code you provided above, how many e-mails does it send out to a user?

The bad part about this script is that it sends out a warning email whenever a new email is received.

nwkit wrote:i checked one of mine and it sent out 3 emails. I have the settings to show the warning at 0.05. I checked the emails that i have received and the size is not even close to 5% left of the quota. (for eg. 29 mb size, and 50 mb quota).

I never had an issue with the quota % not being calculated correctly, but if you turned on the script logging (in the script, this isn't the same thing as hMailServer's logs), you could probably see what the issue was.

nwkit wrote:Is it possible to send out one e-mail a week or something? Instead of multiple e-mails. Thanks.

It would be possible to change this behavior if you stored the last time a warning was sent out in a flat file or something, but that is added complexity that I didn't feel like adding at the time. If someone else wanted to extend the scripts capabilities, that would be great.

'*************************************************************** 'DisposeVariables: Clean up any variables we might have been using ' '*************************************************************** Sub DisposeVariables DebugLog.Dispose Set DebugLog = Nothing End Sub

'*************************************************************** 'DisposeVariables: Clean up any variables we might have been using ' '*************************************************************** Sub DisposeVariables DebugLog.Dispose Set DebugLog = Nothing End Sub

but dont get me wrong - i dont want to complain - so far its working great!

maybe a quick question - i have the quota script implemented without any problems so far but now one of my users came over and complaint about all the "Warnings" about his nearly full mailbox. So i jumped on the system and according to the "Size" vs. "Max Size" he was only running on 10% of his mailbox space (he had about 10Mb on a mailbox with max of 100Mb) So the space thing should be fine but the user still got the Warnings.

Any idea where i can check what could cause this? Or force it to recalculate the space? (The System is running on 5.1.2-B346 with a MSSQL Express Database)

Yeah, scroll down a little bit & read the rest of what he said.. Supposedly the scripts work with hmail 5 but it might take slight changes as noted in the numerous posts in this thread about it..Bill

*** ABSENT FROM hMail! Those in IRC know how to find me if urgent. ***hMailServer build LIVE on my servers: 5.4-B2014050402Latest test builds: http://www.hmailserver.com/forum/viewtopic.php?f=10&t=21420

Bill48105 wrote:Yeah, scroll down a little bit & read the rest of what he said.. Supposedly the scripts work with hmail 5 but it might take slight changes as noted in the numerous posts in this thread about it..Bill

'***************************************************************'DisposeVariables: Clean up any variables we might have been using''***************************************************************Sub DisposeVariables DebugLog.Dispose Set DebugLog = NothingEnd Sub

Thanks again for all of the help fellas. Here is my code which is running on 5.3.3 b1879. This code difers a bit from Topper's code post because it sends a extra copy of the email to an additional mail recipient (in my case it send a copy to the company mail administrator).

This code is running on my server and it appears to be functioning Qorrectly. But that's correct with a "Q" so be very Qareful!

'***************************************************************'MAILBOX QUOTA CHECK & NOTIFICATION'***************************************************************'(From http://www.hmailserver.com/forum/viewtopic.php?f=14&t=2382)'When you test the script,you can turn the Const conDebug = true,'then the system will ouput the debug file,it's helpful.'Every time when you edit the script, you should "check syntax"'and then "reload scripts"'***************************************************************

Dim DebugLog

'***************************************************************'MAILBOX QUOTA CHECK & NOTIFICATION'USER DEFINED CONSTANTS FOR MAILBOX QUOTA NOTIFICATION'***************************************************************'Location of the Log Directory Where Debug log is storedConst conLogDir = "D:\hMailServer\Logs\"'Percentage of space remaining when warning messages get sent (.8 = 80%)Const conSpaceRemainingWarningAt = 0.8Const strAuthenicateName = "Administrator"Const strAuthenicatePwd = "MyhMailPassword"'Email Address that warning emails appear to be send fromConst conSpaceWarningFrom = "admin@MyDomaino.com"'Name of person to send a copy of the message to someone, maybe the mail administratorConst strSendCopyToName = "Email Administrator"'Email address of person to send a copy of the message to someone (maybe the mail administrator?)Const strSendCopyToEmailAddress = "admin@MyDomain.com"'Email subjectConst conSpaceWarningSubject = "*WARNING* Your company email storage is almost full!"'Email messageConst conSpaceWarningBody = "-------- Start of System Warning Message --------\n\nYour company mailbox size is presently [size] of its [maxsize] MB allowed size (it is now more then 80% full).\n\nIf you reach 100% you will won't be able to receive any new emails.\n\nPlease contact your company email administrator for help with this issue.\n\n--------- End of System Warning Message ---------"'If True, debug log is created to help debugConst conDebug = false'***************************************************************

Is it possible to check the subject of all e-mails on the mailbox if there is already a limit warning message sent earlier?. So the user don’t receiver several limit warnings messages if he is not reading his e-mail for a while.

This is a very good idea Greta. When this script fires the user will receive a warning each time he/she receives an email. It would be better to send one (1) warning per day imho. However, scripting this is well beyond my Qapabilities.

mattg wrote:running once per day is easy enough, run as a scheduled task, and don't run it inside eventhandlers.vbs...

If you have a dedicated server, Matt's advice is very good and less overhead IMO because the script doesn't fire every time mail is received but rather it runs only once a day as an MS Windows scheduled system task...