ADSI和EXCHANGE结合的示范代码

2008-02-23 06:13:55来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

在独孤九剑兄的帮助下,完成了这段代码

包括NT用户的建立,EXCHANGE邮箱的建立,两者的结合,权限的配置

bitsCN.nET中国网管博客

本代码在nt4.0 sp6 exchange5.5 adsi2.5下运行通过

bitscn.com

建立以后的用户能够直接收发信件,是个简化版本的WEB MAIL ACCESS BBS.bitsCN.com网管论坛

adsi_exchange.asp
-----------------------------------------------------------------------

www_bitscn_com

<%
Set sid = CreateObject("ADsSID")
Set sec = CreateObject("ADsSecurity")
Set ace = CreateObject("AccessControlEntry") 中国.网管联盟


'----------------------------------------------------------------------------
'--- 假如没有安装ADSI2.5的安全库要手工定义以下参数
'-----------------------------------------------------------------------------
Const ADS_SID_HEXSTRING = 1
Const ADS_SID_WINNT_PATH = 5
Const ADS_RIGHT_EXCH_MODIFY_USER_ATT = &H2
Const ADS_RIGHT_EXCH_MAIL_SEND_AS = &H8
Const ADS_RIGHT_EXCH_MAIL_RECEIVE_AS = &H10 bbs.bitsCN.com


'-------------------------------------------------------
'-----创建邮箱步骤----------------------
'-------------------------------------------------------- bitsCN.Com

'---- 基本信息
server1 = "114DOMAINSERVER"
Org = "114ONLINE"
Site = "EXCHANGE"
domain = "EXCHANGE"
userName = "liuoo"
password = "43444"

BBS.bitsCN.com网管论坛

'--- 邮箱信息 -----
strDisplayName = "rtrtrt"
strFirstName = "gfgf"
strLastName = "fgfgfg"
strAlias = userName
strMTA = "cn=Microsoft MTA,cn=" & server1 & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
strMDB = "cn=Microsoft Private MDB,cn=" & server1 & ",cn=Servers,cn=Configuration,ou=" & Site & ",o=" & Org
strSMTPAddr = "ewwe@114online.com" 中国网管论坛


'------ 建立一个nt用户
Set dom = GetObject("WinNT://" & domain)
Set usr = dom.Create("user", userName)
'On Error Resume Next
usr.SetInfo
'If Err.Number <> 0 Then
' Response.Write "111"
' Response.Write Err.Description
' Response.End
'End If
usr.SetPassword password

中国网管论坛


'--- 创建邮箱
ADsPath = "LDAP://" server1
ADsPath = ADsPath "/cn=Recipients,OU="
ADsPath = ADsPath Site
ADsPath = ADsPath ",O="
ADsPath = ADsPath Org

BBS.bitsCN.com网管论坛

bitsCN_com

Set objCont = GetObject(ADsPath)

BBS.bitsCN.com网管论坛

'Create a new MailBox
Set mailBox = objCont.Create("organizationalPerson", "cn=" & strAlias)
mailBox.Put "mailPreferenceOption", 0
mailBox.Put "givenName", strFirstName
mailBox.Put "sn", strLastName
mailBox.Put "cn", strDisplayName
mailBox.Put "uid", strAlias
mailBox.Put "Home-MTA", strMTA
mailBox.Put "Home-MDB", strMDB
mailBox.Put "mail", strSMTPAddr
mailBox.Put "MAPI-Recipient", True
mailBox.Put "rfc822Mailbox", strSMTPAddr

DL.bitsCN.com网管软件下载

'--------------------------------------------------------
' 和nt用户联系
'---------------------------------------------------------
sid.SetAs ADS_SID_WINNT_PATH, "WinNT://" & domain & "/" & strAlias & ",user"
sidHex = sid.GetAs(ADS_SID_HEXSTRING)
mailBox.Put "Assoc-NT-Account", sidHex

bitsCN_com

' 完成配置
mailBox.SetInfo

bitsCN_com

www.bitsCN.com

'-------------------------------------------------
'更改安全配置
'-------------------------------------------------
Set sd = sec.GetSecurityDescriptor(mailBox.ADsPath)
Set dacl = sd.DiscretionaryAcl
ace.Trustee = domain & "\" & strAlias
ace.AccessMask = ADS_RIGHT_EXCH_MODIFY_USER_ATT Or ADS_RIGHT_EXCH_MAIL_SEND_AS Or ADS_RIGHT_EXCH_MAIL_RECEIVE_AS
ace.AceType = ADS_ACETYPE_ACCESS_ALLOWED
dacl.AddAce ace
sd.DiscretionaryAcl = dacl
sec.SetSecurityDescriptor sd bitsCN.Com

response.write "successful"
%>

bitsCN.Com

------------------------------------------------------------------------
请注意权限的配置
bitscn.com

,

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇: Exchange Server中配置大小限制

下一篇: Exchange通讯服务巧实现

热门词条
热门标签