近日逼不得已必須用asp創建EXCHANGE 2000用戶,但以前的相似文章都是關於Exchange 5。5的,而且明確說明不向後兼容,因此在MSDN網站游蕩了很久,終於找到一點資料,經過改編,終於能用於ASP。
此段ASP的執行的環境在W2K+IIS5,並且必須要有足夠的權限。
如有不當之處,請高手指正。
<%@ Language=VBScript %>
<Html>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 7.0">
</HEAD>
<BODY>
<%
Dim objUser
Dim objContainer
Dim objmailbox
Dim recipname, recip
Dim ServerName, DomainName, emailname, FirstName, LastName, passWord
ServerName = "skyWord.PRogram.org"
DomainName = "DC=program,DC=org"
emailname = "test"
passWord = "1234"
recip = "CN=" & emailname
LastName = "sky"
FirstName = "Word"
Set objContainer = GetObject("LDAP://" & ServerName & "/OU=China.org," & DomainName)
Set objUser = objContainer.Create("User", recip)
objUser.Put "saMaccountName", emailname
objUser.Put "sn", LastName
objUser.Put "givenName", FirstName
objUser.Put "DisplayName", "[email protected]"
objUser.Put "userPrincipalName", emailname & "@China.org"
objUser.SetInfo
objUser.SetPassword passWord
objUser.AccountDisabled = False
objUser.SetInfo
Set objMailbox = objUser
objMailbox.CreateMailbox "LDAP://skyword.program.org/CN=Mailbox Store (SKYWORD),CN=First Storage Group,CN=InformationStore,CN=SKYWord,CN=Servers,CN=First Administrative Group,CN=Administrative Groups,CN=ecitye,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=program,DC=org"
objUser.SetInfo
Set objContainer = Nothing
Set objUser = Nothing
Set objMailbox = Nothing
if err <> 0 then
Response.Write "失敗"
else
Response.Write "成功!!!"
end if
%>
</BODY>
</Html>
注:如果使用此代碼,請注意你的機器上的LDAP不同。有關ADSI和LDAP的文章在精華有介紹,加上我也不太懂就不介紹了。 ;)