These two scripts have been placed here to make them easier to get at and replace the two scripts at end of following topic.
viewtopic.php?p=155678#p155678
These two scripts are for the purpose of whitelisting any recipients that you send email to. The main benefit is that it allows any external incoming email address that you have sent email, to bypass greylisting when they send their first mail to you and are not dependant on their mail servers smtp retry period which can delay you from receiving their email quickly. i.e. if you need a mail from someone external quickly and you are running greylisting, then just send them an email they can respond to and it should get through to you on their first attempt without being bounced with a 451 temporary failure message to them..
Note: script will only whitelist them to send to your user sending address and not to any other user at your own domain.
Auto Whitelist
The potential downsides to this script are, firstly it may quickly build a very large whitelist if you are sending to hundreds or more recipients. And secondly because it has to trawl through the full whitelist to check if the address is already in list(no method available to read by email address), it will become slow if the list grows to hundreds or more entries. But then again, it isn't using any external files with open and closes which slows down hMail. There is a cleanup script below so whitelist size can be managed to not grow too big with dormant entries.
Also no Spam checking on anything in whitelist, i.e. when you send to anyone then anything they send to you is not spam checked.
I did quick testing and it seems to work fine with gmail address I tested with greylisting switched on. i.e. it created whitelist and then it let gmail address straight through.
Place code in your onAcceptMessage Sub (in eventhandlers vbs) and set your admin password in code. Save and reload scripts. It's as simple as that.
Code: Select all
'--------------------------------------------------------
' Auto Whitelist recipients from auth'd senders
'--------------------------------------------------------
If oClient.Port = 25 Then ' set your smtp sending port number here
If oClient.Username <> "" Then
Dim oApp
Dim oWhitelistAddresses
Dim oWhitelistAddress
Dim oRecipient
Dim InWhiteList
InWhiteList = False
Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator","password") ' set your administrator password in this line
Set oWhitelistAddresses = oApp.Settings.AntiSpam.WhiteListAddresses
For oRecipient = 0 to oMessage.Recipients.Count-1
If Not oMessage.Recipients(oRecipient).IsLocalUser Then
For oWhitelistAddress = 0 to oWhitelistAddresses.Count-1
If oWhitelistAddresses(oWhitelistAddress).EmailAddress = oMessage.Recipients(oRecipient).Address Then
oWhitelistAddresses(oWhitelistAddress).Description = Date & " Auto Add Recipient " & oMessage.Recipients(oRecipient).Address
oWhitelistAddresses(oWhitelistAddress).Save
InWhiteList = True
Exit For
End If
Next
If Not InWhiteList Then
Set oWhitelistAddress = oWhitelistAddresses.Add
oWhitelistAddress.LowerIPAddress = "0.0.0.0"
oWhitelistAddress.UpperIPAddress = "255.255.255.255"
oWhitelistAddress.emailaddress = oMessage.Recipients(oRecipient).Address
oWhitelistAddress.description = Date & " Auto Add Recipient " & oMessage.Recipients(oRecipient).Address
oWhitelistAddress.Save
End If
End If
Next
End If
End If
'--------------------------------------------------------
Following code should be saved in a new file. Call it WhitelistCleanup.vbs and place the file in your hmailserver/events folder.
You can run it manually by double clicking on it and/or you can setup a windows scheduled task to run it every day.
It deletes entries added by above whitelist script which are older than x days. Just make sure the description contains "Auto Add Recipient" in both scripts.
The effect is to remove anyone from the whitelist you have not been communicating with for the last x days so that the whitelist doesn't become too big.
Code: Select all
'Force error on undeclared variables
Option Explicit
'--------------------------------------------------------------------------
' Cleanup of Whitelist entries created with Auto Add Recipient to whitelist
'--------------------------------------------------------------------------
Dim oApp
Dim oWhitelistAddresses
Dim oWhitelistAddress
Dim Days
Days = 180 ' *** set age in days of Auto Add Recipient whitelist entries to be deleted
Dim WLDate
Dim oEventLog
Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator","password") ' set your administrator password in this line
Set oEventlog = CreateObject("hMailServer.EventLog")
Set oWhitelistAddresses = oApp.Settings.AntiSpam.WhiteListAddresses
For oWhitelistAddress = oWhitelistAddresses.Count-1 to 0 Step -1
if (InStr(1, oWhitelistAddresses(oWhitelistAddress).Description, "Auto Add Recipient", 1) > 0) Then
WLDate = Mid(oWhitelistAddresses(oWhitelistAddress).Description,1,10)
if DateDiff("d", WLDate, Date) >= Days then
oEventLog.Write("Whitelist Delete: " & oWhitelistAddresses(oWhitelistAddress).EmailAddress)
oWhitelistAddresses(oWhitelistAddress).Delete
End If
End If
Next