Block Domains

This section contains scripts that hMailServer has contributed with. hMailServer 5 is needed to use these.
Post Reply
bescher
Normal user
Normal user
Posts: 123
Joined: 2008-05-26 01:56
Location: Milwaukee Wi
Contact:

Block Domains

Post by bescher » 2012-04-26 21:17

I would like to block a domain completely.
I have tried using *@domain.com
using *@*.com
as well and it doesn't work
How do I create a rule
The above was a contains

Thanks

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

Re: Block Domains

Post by ^DooM^ » 2012-04-26 22:45

Rules are matched to the SMTP Envelope address. Check the logs to see which domain they are actually sending from.
If at first you don't succeed, bomb disposal probably isn't for you! ヅ

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: Block Domains

Post by percepts » 2012-04-27 06:38

also possible to block from eventhandlers.vbs script using following to replace commented out OnAcceptMessage section.

Sub OnAcceptMessage(oClient, oMessage)
if (InStr(1, oMessage.FromAddress, "full or part email address goes in here", 1) > 0) Then
Result.Value = 1
End If

If (Result.Value = 1 ) Then ' Rejected
EventLog.Write("Mail reject:"+Chr(34)+vbTab+oMessage.FromAddress+vbTab+Chr(34)+" ")
End if
End Sub

bescher
Normal user
Normal user
Posts: 123
Joined: 2008-05-26 01:56
Location: Milwaukee Wi
Contact:

Re: Block Domains

Post by bescher » 2012-04-28 08:42

Thanks again Percepts

While we are at it is there a script to call a blacklist (txt file) of domains
I know that everyone says it's bad but I have always had good success with it in 12 years. (or add domain onto the below
so it would be for example? I am not a programmer. can do some php but that's it

Sub OnAcceptMessage(oClient, oMessage)
if (InStr(1, oMessage.FromAddress, "*@*.com", 1) > 0) Then
Result.Value = 1
End If

If (Result.Value = 1 ) Then ' Rejected
EventLog.Write("Mail reject:"+Chr(34)+vbTab+oMessage.FromAddress+vbTab+Chr(34)+" ")
End if
End Sub

percepts
Senior user
Senior user
Posts: 5282
Joined: 2009-10-20 16:33
Location: Sceptred Isle

Re: Block Domains

Post by percepts » 2012-04-29 05:28

vbscript is no more complex than PHP and I have only ever cobbled together any vbscript. I don't know if there are any scripts out there that already do what you want but I doubt it.

the eventhandler.vbs script just executes certain subs at certain points during the processing of mailserver communications. You'll have to read the documentation and look to see if there any api calls you can utilise. Since vbscript is available I guess you could do it from the OnClientConnect sub and make it read a txt file and set the return code accordingly. Shouldn't be too difficult if you have the will to do it.

glenluo
Normal user
Normal user
Posts: 194
Joined: 2011-07-03 12:10

Re: Block Domains

Post by glenluo » 2012-05-10 00:59

my script to block domians(Set it at :Sub OnAcceptMessage(oClient, oMessage)):

Code: Select all

Dim FSO,txtfile,strtxt
If oMessage.FromAddress<>"" Then 
set FSO=CreateObject("Scripting.FileSystemObject")
Set txtfile = FSO.OpenTextFile("E:\hMailServer\Events\Black_Domain.txt",1,TriStateTrue)
Do Until txtfile.AtEndOfStream
strtxt = Trim(txtfile.ReadLine)
If (InStr(1,oMessage.FromAddress,strtxt,1)>0) Then
Result.Value = 2
Result.Message ="Your domain is in the local blacklist,server rejected!"
End if
Loop
txtfile.Close
End if

bescher
Normal user
Normal user
Posts: 123
Joined: 2008-05-26 01:56
Location: Milwaukee Wi
Contact:

Re: Block Domains

Post by bescher » 2012-05-10 16:25

I tried implementing the above script.
But I kep on geeting error messages at line 81
end if statement

Below is my script
Where do I put the above so I don't get the if end error message

Thank you

Sub OnClientConnect(oClient)
Dim geoip
Result.Value =1
set geoip = CreateObject("GeoIPCOMEx.GeoIPEx")
geoip.set_db_path("c:\Program files\hmailserver\geoip\")
geoip.find_by_addr(oClient.IPAddress)
country = geoip.country_code

If (country = "LH" ) Then
Result.Value = 0
End if
If (country = "LN" ) Then
Result.Value = 0
End if
If (country = "GB" ) Then
Result.Value = 0
End if
If (country = "US" ) Then
Result.Value = 0
End if
If (country = "SE" ) Then
Result.Value = 0
End if
If (country = "DE" ) Then
Result.Value = 0
End if
If (country = "CA" ) Then
Result.Value = 0
End if
If (Result.Value = 1 ) Then ' Rejected
EventLog.Write("Geo-IP rejected:"+Chr(34)+vbTab+oClient.IPAddress+vbTab+Chr(34) +geoip.country_code+" "+geoip.country_name)
End if
End Sub


' Sub OnAcceptMessage(oClient, oMessage)


' End Sub

' Sub OnDeliveryStart(oMessage)
' End Sub

' Sub OnDeliverMessage(oMessage)
' End Sub

' Sub OnBackupFailed(sReason)
' End Sub

' Sub OnBackupCompleted()
' End Sub

' Sub OnAcceptMessage(oClient, oMessage)
' End Sub

' Sub OnDeliverMessage(oMessage)
' End Sub

' Sub OnBackupFailed(sReason)
' End Sub

' Sub OnBackupCompleted()
' End Sub

Sub OnAcceptMessage(oClient, oMessage)
If oClient.Username <> "" Then
If LCase(oClient.Username) <> LCase(oMessage.FromAddress) Then
Result.Value = 2
Result.Message = "You are only allowed to send from your own account"
End If
End If
End Sub

glenluo
Normal user
Normal user
Posts: 194
Joined: 2011-07-03 12:10

Re: Block Domains

Post by glenluo » 2012-05-15 10:55

You need ti add then between "Sub OnAcceptMessage(oClient, oMessage)" and "End Sub"

Post Reply