分页: 1 / 1

限制某个账号外发

发表于 : 2015年4月11日, 10:49
Hsia
下面这个是限制某个用户发外域。修改EventHandlers.vbs

代码: 全选

Sub OnSMTPData(oClient, oMessage)
   If (oClient.Username <> "") Then
      Const NotPermitted = "xxxxx@xx.com"
      Dim i
      If InStr(NotPermitted, oClient.Username) Then
         For i = 0 To oMessage.Recipients.Count -1
            If (Not oMessage.Recipients(i).IsLocalUser) Then
               Result.Value = 2
               Result.Message = "You are only allowed to send internally"
            End If
         Next
      End If
   End If
End Sub
有时候,在全公司,只有老板或者一部分特殊职位的用户可以发到外部,在这种情况下,基本所有的账号就只能在内部发。我们利用下面的脚本就可以实现。(例如,每个人都被允许除在仓库中的逃学的家伙 ),一旦你决定哪种方法适用于您的业务,为您打造一个通讯组列表相应标题,或者:“ AllowedSenders “或“ NonSenders “ 在该通讯组列表,你再进入适用于列表中的人员的电子邮件地址成员(按标题)。请记住,没有出现在列表中的用户将被允许做相反的。你不需要维护两个列表-你只需要实现一个。一旦你创建了相关的通讯组列表,那么你复制代码仅该脚本之一以下,确保您选择正确的脚本根据您的通讯组列表的选择/称号。该脚本应该被添加到“eventhandlers.vbs'脚本。脚本1:ALLOWEDSENDERS -阻止所有除了那些通讯组列表

代码: 全选

Sub OnSMTPData(oClient, oMessage)
   If (oClient.Username <> "") 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
         End If
      Next
   End If
End Sub
脚本2:NONSENDERS -允许,除了那些在分发列表中

代码: 全选

Sub OnSMTPData(oClient, oMessage)
   If (oClient.Username <> "") 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
         End If
      Next
   End If
End Sub
原文地址:https://www.hmailserver.com/forum/viewt ... 20&t=28045

Re: 限制某个账号外发

发表于 : 2015年5月8日, 09:12
jasonshaw
mark一下,等需要的时候来学习

Re: 限制某个账号外发

发表于 : 2016年3月19日, 10:41
JACKWANG0823
特别 mark 专心学习 。。。 楼主 这些代码要写在那个位置啊

Re: 限制某个账号外发

发表于 : 2016年3月20日, 16:38
Hsia
JACKWANG0823 写了:特别 mark 专心学习 。。。 楼主 这些代码要写在那个位置啊
hMailServer\Events\EventHandlers.vbs

然后在hMailServer管理面板,设置-高级-脚本 (启用)。修改后必须 点击重新载入脚本, 方可生效。

Re: 限制某个账号外发

发表于 : 2018年5月4日, 10:39
myadmin
感谢分享