Newbie: send Quota-Message to Client

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
Lengen1971
Normal user
Normal user
Posts: 32
Joined: 2010-05-10 12:40

Newbie: send Quota-Message to Client

Post by Lengen1971 » 2010-05-10 12:45

Hi,
lately startet with scripting the hMailServer.

So, may you help with starting up a script, that tells the User, when its mailbox-quota is to high.

1. the script must reside in EventHandlers.vbs
2. which Event can I use?
3. how to identify the user currrently fetches mail?

w/regards
Michael

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Newbie: send Quota-Message to Client

Post by ^DooM^ » 2010-05-10 14:19

Have you checked out the user contributed scripts section? There maybe something in their for you to use.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

Lengen1971
Normal user
Normal user
Posts: 32
Joined: 2010-05-10 12:40

Re: Newbie: send Quota-Message to Client

Post by Lengen1971 » 2010-05-10 14:54

Hi and thanx for your answer,

do you mean Support-Scripts here in this forum? I can´t find something useful for my problem.

Or where do I find this Script-Section you talk about?

regards
Michael

^DooM^
Site Admin
Posts: 13861
Joined: 2005-07-29 16:18
Location: UK

Re: Newbie: send Quota-Message to Client

Post by ^DooM^ » 2010-05-10 15:19

If at first you don't succeed, bomb disposal probably isn't for you! ヅ

User avatar
ras07
Normal user
Normal user
Posts: 228
Joined: 2010-03-11 08:51

Re: Newbie: send Quota-Message to Client

Post by ras07 » 2010-05-10 21:10

I recently looked for such a script; there was a v4 one, but it was rather involved. It looked like it would be a lot easier in v5, so I wrote one:

Code: Select all

'====================================================================================

Sub WarnQuotaMiscreants(MiscreantName, MiscreantAddress)

'------------------------------------------------------------------------------------------------
'  Sends a warning email if this user is are approaching their mailbox quota. 
'  Can be triggered when the potential miscreant sends email, receives email, on a nightly
'  or weekly schedule, etc.
'------------------------------------------------------------------------------------------------
Const hMSAuthUser		= "user"			' Username of hMailServer administrator
Const hMSAuthPass		= "password"	' Password of hMailServer administrator
Const WarnFrom      = "Administrator"
Const WarnFromAddr  = "postmaster@yourdomain.com"
Const WarnThreshold = 85		' Percent quota used that will trigger warning email
Const WarnMsgSubj   = "WARNING: You are close to exceeding your mailbox quota!"
Dim WarnMsgBody
WarnMsgBody = "Your mailbox is now at $$PCTCAPACITY$$% capacity. " & _
	    " If you exceed your mailbox capacity, you will not be able to receive email, " & _
	    "and incoming email to your account will be rejected. Reduce your mailbox size " & _
	    "by deleting old emails or moving them to local folders. " & vbCRLF & vbCRLF & _
	    "Note that your mailbox quota includes all folders - Inbox, Sent, etc. - and even " & _
	    "the Trash folder, if it isn't routinely emptied automatically by your email " & _
	    "client or manually by you. "

	Dim WarnMsg
	Set WarnMsg = CreateObject("hMailServer.Message")
	Call WarnMsg.AddRecipient(MiscreantName, MiscreantAddress)
	If Not WarnMsg.Recipients(0).IsLocalUser Then 
		Exit Sub 	' don't bother if it's not a local address
	End If

	Dim oApp, oAcct
	Set oApp = CreateObject("hMailServer.Application")
	Call oApp.Authenticate(hMSAuthUser, hMSAuthPass)
	
	'	This small bit of convolution is necessary to handle aliases.
	Dim DomainName
	DomainName = LCase(Mid(WarnMsg.Recipients(0).Address, _
			InStr(WarnMsg.Recipients(0).Address, "@")+1))
	Set oAcct = oApp.Domains.ItemByName(DomainName).Accounts.ItemByAddress(WarnMsg.Recipients(0).Address)

	'	Check the quota used, and send the message if it's over the threshold.
	If (oAcct.QuotaUsed >= WarnThreshold) Then
		LogStr("Sending mailbox quota warning to " & WarnMsg.Recipients(0).Address & _
				" (" & oAcct.QuotaUsed & "%)")
		warnMsg.From = WarnFrom
		warnMsg.FromAddress = WarnFromAddr
		warnMsg.Subject = WarnMsgSubj
		warnMsg.Body = Replace(WarnMsgBody, "$$PCTCAPACITY$$", CStr(oAcct.QuotaUsed))
		warnMsg.Save
	End If

End Sub 'WarnQuotaMiscreants(MiscreantName, MiscreantAddress)

'===================================================================================
This goes in EventHandlers.vbs and is called from OnAcceptMessage. I call it when a user sends email, like so:

Code: Select all

	Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
It could just as easily be called when the user receives email. It would be trickier to trigger it when a user checks their email. This works for me.

I suppose I should get around to posting this in the user contributed script section ...

Hope this helps
ras

Lengen1971
Normal user
Normal user
Posts: 32
Joined: 2010-05-10 12:40

Re: Newbie: send Quota-Message to Client

Post by Lengen1971 » 2010-05-11 09:33

Hi everybody,

thanx a lot for your messages and solutions. I will now try this out and look forward to understand
the code.

regards
Michael

Lengen1971
Normal user
Normal user
Posts: 32
Joined: 2010-05-10 12:40

Re: Newbie: send Quota-Message to Client

Post by Lengen1971 » 2010-05-11 09:58

Hi,

@rus07: Thank you a lot. Your script works fine, that was what I´m looking for.

Only this line throws an error:

Code: Select all

LogStr("Sending mailbox quota warning to " & WarnMsg.Recipients(0).Address & _
       " (" & oAcct.QuotaUsed & "%)")
Error:
"ERROR" 480 "2010-05-11 09:48:17.543" "Script Error: Source: Laufzeitfehler in Microsoft VBScript - Error: 800A000D - Description: Typen unverträglich: 'LogStr' - Line: 42 Column: 6 - Code: (null)"
I think this means: Type mismatch

w/regards
Michael

User avatar
ras07
Normal user
Normal user
Posts: 228
Joined: 2010-03-11 08:51

Re: Newbie: send Quota-Message to Client

Post by ras07 » 2010-05-11 17:50

Lengen1971 wrote:Hi,

@rus07: Thank you a lot. Your script works fine, that was what I´m looking for.

Only this line throws an error:

Code: Select all

LogStr("Sending mailbox quota warning to " & WarnMsg.Recipients(0).Address & _
       " (" & oAcct.QuotaUsed & "%)")
Error:
"ERROR" 480 "2010-05-11 09:48:17.543" "Script Error: Source: Laufzeitfehler in Microsoft VBScript - Error: 800A000D - Description: Typen unverträglich: 'LogStr' - Line: 42 Column: 6 - Code: (null)"
I think this means: Type mismatch
Oops, I missed that ... you can just delete that line, it just writes to a log file - doesn't do anything for the script

coby
New user
New user
Posts: 12
Joined: 2008-12-04 18:57

Re: Newbie: send Quota-Message to Client

Post by coby » 2011-02-20 17:13

could someone help me to get this script working?

i have added this to the EventHandlers.vbs

Code: Select all

   'Sub OnAcceptMessage(oClient, oMessage)
Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
   'End Sub
and where the other code comes? in a *. vbs file or in the EventHandlers.vbs ?

i got no error message

and i delete the whole line for logging

Code: Select all

LogStr("Sending mailbox quota warning to " & WarnMsg.Recipients(0).Address & _
       " (" & oAcct.QuotaUsed & "%)")

*sorry for my bad english*

User avatar
mattg
Moderator
Moderator
Posts: 20792
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Newbie: send Quota-Message to Client

Post by mattg » 2011-02-21 01:31

coby wrote:could someone help me to get this script working?

i have added this to the EventHandlers.vbs

Code: Select all

   'Sub OnAcceptMessage(oClient, oMessage)
Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
   'End Sub
You need to un-comment the sub and the end sub lines
(remove the leading ')

Code: Select all

   Sub OnAcceptMessage(oClient, oMessage)
Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
   End Sub
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

coby
New user
New user
Posts: 12
Joined: 2008-12-04 18:57

Re: Newbie: send Quota-Message to Client

Post by coby » 2011-02-21 17:38

mattg wrote:
coby wrote:could someone help me to get this script working?

You need to un-comment the sub and the end sub lines
(remove the leading ')

Code: Select all

   Sub OnAcceptMessage(oClient, oMessage)
Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
   End Sub
done.

and where does the other code comes in? in a new *. vbs file or in the EventHandlers.vbs ?

coby
New user
New user
Posts: 12
Joined: 2008-12-04 18:57

Re: Newbie: send Quota-Message to Client

Post by coby » 2011-02-21 18:17

coby wrote:
mattg wrote:
coby wrote:could someone help me to get this script working?

You need to un-comment the sub and the end sub lines
(remove the leading ')

Code: Select all

   Sub OnAcceptMessage(oClient, oMessage)
Call WarnQuotaMiscreants(oMessage.From, oMessage.FromAddress)
   End Sub
done.

and where does the other code comes in? in a new *. vbs file or in the EventHandlers.vbs ?
i got this script to in my eventhandlers.vbs

http://www.hmailserver.com/forum/viewto ... 20&t=14280

and where does the other code comes in? in a new *. vbs file or in the EventHandlers.vbs ?

User avatar
mattg
Moderator
Moderator
Posts: 20792
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Newbie: send Quota-Message to Client

Post by mattg » 2011-02-22 02:17

I didn't write it, but I expect that it also gets added to your eventhandlers.vbs file. This is the ONLY file loaded by hMailserver.

You will need to re-load the scripts and test for the expected outcomes...
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply