It may be that you have a requirement to allow some users to send emails to external addresses whilst restricting other users (permitting only internal mails).
The scripts operate by referring to a specific DISTRIBUTION LIST against your domain containing the member addresses of the users that you wish to allow/block (depending on the script chosen). They work on the proviso that senders AUTHENTICATE to send emails and that you authenticate using the full 'user@domain.com' format.
Either of the following scripts should be used depending on your chosen scenario:
a, "ALLOWEDSENDERS" : the MAJORITY of users are RESTRICTED from sending external emails by default, and so it is easier to maintain a list of users that are allowed (for example, maybe only managers of a company are allowed, and all others are restricted)
b, "NONSENDERS" : this should be used where MAJORITY are ALLOWED by default, yet you want to restrict a minority of users from sending to external addresses. (eg, everyone is allowed except the hooky bloke in the warehouse

Once you have decided on which method applies to your business, you create a Distribution List titled accordingly, either:
"AllowedSenders" or
"NonSenders"
Remember to keep the identity/existence of this distribution list secret from users to avoid it being sent to.
Within that distribution list you then enter the email member addresses of the people THAT APPLY to the list (according to the title). Remember that users that do NOT appear on the list will be allowed to do the contrary. You do not need to maintain BOTH lists - you only need to implement one.
Once you have created the relevant distribution list, then you copy the code FROM ONLY ONE of the scripts below ensuring you choose the correct script according to the choice/title of your distribution list. The script should be added to the 'eventhandlers.vbs' script. DONT FORGET to change the password to match your HMS system password (currently coded as "*secretpassword*").
Script 1:
ALLOWEDSENDERS - blocking all except those entered in the distribution list
Code: Select all
Sub OnSMTPData(oClient, oMessage)
If oClient.Username <> "" and instr(oClient.Username, "@") > 0 Then
Dim k, i, j, aUsername, oApp, oDomain, oDistributionList
Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", "*secretpassword*")
aUsername = Split(oClient.Username,"@")
Set oDomain = oApp.Domains.ItemByName(aUsername(1))
For k = 0 To oDomain.DistributionLists.Count -1
If lcase(oDomain.DistributionLists.Item(k).Address) = lcase("AllowedSenders@" & aUsername(1)) Then
Set oDistributionList = oDomain.DistributionLists.Item(k)
if oDistributionList.Active then
For j = 0 To oMessage.Recipients.Count -1
If (Not oMessage.Recipients(j).IsLocalUser) Then
For i = 0 To oDistributionList.Recipients.Count -1
If lcase(oDistributionList.Recipients.Item(i).RecipientAddress) = lcase(oClient.Username) Then
Exit Sub
End If
Next
Result.Value = 2
Result.Message = "You are only allowed to send internally"
End If
Next
End If
Exit For
End If
Next
End If
End Sub
or
Script 2:
NONSENDERS - Allowing all except those listed in the distribution list.
Code: Select all
Sub OnSMTPData(oClient, oMessage)
If oClient.Username <> "" and instr(oClient.Username, "@") > 0 Then
Dim k, i, j, aUsername, oApp, oDomain, oDistributionList
Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate("Administrator", "*secret password*")
aUsername = Split(oClient.Username,"@")
Set oDomain = oApp.Domains.ItemByName(aUsername(1))
For k = 0 To oDomain.DistributionLists.Count -1
If lcase(oDomain.DistributionLists.Item(k).Address) = lcase("NonSenders@" & aUsername(1)) Then
Set oDistributionList = oDomain.DistributionLists.Item(k)
if oDistributionList.Active then
For j = 0 To oMessage.Recipients.Count -1
If (Not oMessage.Recipients(j).IsLocalUser) Then
For i = 0 To oDistributionList.Recipients.Count -1
If lcase(oDistributionList.Recipients.Item(i).RecipientAddress) = lcase(oClient.Username) Then
Result.Value = 2
Result.Message = "You are only allowed to send internally"
Exit Sub
End If
Next
End If
Next
End If
Exit For
End If
Next
End If
End Sub