Global Mail Filter

Discussion forum for Enterprise Edition.
Post Reply
tech4u
Posts: 11
Joined: Wed Aug 24, 2016 11:11 am

Global Mail Filter

Post by tech4u »

I am trying to implement a complex filter but the tokens do not seem to work.

Code: Select all

Dim FSO, fname
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fname = fso.OpenTextFile("C:\Test\MTA-log.txt", 8, True, 0)

fname.WriteLine "--- " & Now & " ---"
fname.WriteLine "ME_TOorCC = " & CStr([ME_TOorCC])
fname.WriteLine "ME_CC = " & [ME_CC]
fname.WriteLine "ME_TO = " & [ME_TO]
fname.WriteLine "ME_BODY = " & [ME_BODY]
fname.WriteLine "ME_IPADDRESS = " & [ME_IPADDRESS]

dim recipients
recipients = Split( Replace([ME_TO], ",", ";") , ";")
fname.WriteLine "UBOUND(recipients) = " & CStr(UBOUND(recipients))


For Each s in recipients
 fname.WriteLine "Recipient [" & s & "]"
Next

For Each s in recipients
 If CriteriaMet( s ,"*@mytest.local") Then
  fname.WriteLine s & " matches *@mytest.local"
 Else
  fname.WriteLine s & " does not match *@mytest.local"
  result = 1
  Exit For
 End If
Next

FilterResult = result


fname.close
fname = Nothing
FSO = Nothing
In this script I have added debugging (because the registry flag Debug Status does nothing useful). The result is:
--- 26/06/2018 15:27:17 ---
ME_TOorCC = 1
ME_CC = 0
ME_TO = 1
ME_BODY = 1
ME_IPADDRESS = 0
UBOUND(recipients) = 0
Recipient [0]
0 does not match *@mytest.local
I am trying to build a filter that will allow users to send emails to only one domain. The tokens for [ME_TO], [ME_CC], and [ME_TOorCC] all allow messages through if there are multiple recipients and at least one is an allowed domain.

tech4u
Posts: 11
Joined: Wed Aug 24, 2016 11:11 am

Re: Global Mail Filter

Post by tech4u »

After finding https://www.mailenable.com/documentatio ... alues.html this became straightforward.

Code: Select all

Dim recipients, regex, matchResult, s, Result
Set regex = new RegExp
regex.IgnoreCase = True
regex.Pattern = ".+@mytest\.local\]"

recipients = Split( Replace("%RECIPIENTS%", ",", ";") , ";")

For Each s in recipients
 Set matchResult = regex.Execute(s)
 If matchResult.Count <= 0 Then
  Result = 1
  Exit For
 End If
 Set matchResult = Nothing
Next

Set regex = Nothing
FilterResult = Result

Post Reply