Clicky

20150909

TLD filter in hMailserver 5

As I wrote in a previous post hMailserver can be tweaked. In this post I will show a simple TLD filter. This filter is used to block emails from certain Top Level Domains, especially from countries that host many attackers.

Add this code to the hMailserver 'EventHandlers.vbs' script:

Sub OnSMTPData(oClient, oMessage)

'--- Space before the first and after the last country name are required (see TK's comment)...
 Const BlackList=" AR VN CN CO IN BR KE MX TH RO BG KZ TW RU TH "
 Dim TLD

  TLD=Mid(oMessage.FromAddress,Instr(oMessage.FromAddress,".") + 1)
    if Instr(Blacklist,uCase(TLD))>0 then
      Eventlog.Write("OnSMTPdata: TLD in Blacklist " & oMessage.FromAddress & ". 542 Rejected" )
      result.value=1
    End if    
 End Sub

That's all! Happy emailing!

1 comment :

  1. Great article, I had only a small issue.
    When I add .co.uk or .accountant Tlds the filter will also block .co Tld
    I solved issue as follows:
    ' Added a space before and after each TLD
    Const BlackList=" AR VN CN CO IN BR KE MX TH RO BG KZ TW RU TH "
    Dim TLD

    TLD=Mid(oMessage.FromAddress,Instr(oMessage.FromAddress,".") + 1)
    ' Added space before and after TLD
    if Instr(Blacklist," "&uCase(TLD)&" ")>0 then
    Eventlog.Write("OnSMTPdata: TLD in Blacklist " & oMessage.FromAddress & ". 542 Rejected" )
    result.value=1
    End if

    ReplyDelete

Real Time Web Analytics