请教各路大侠,小弟在使用Exchange Server,利用ADSI接口创建用户邮箱,希望得到帮助(200分)

  • 主题发起人 主题发起人 杨先彬
  • 开始时间 开始时间

杨先彬

Unregistered / Unconfirmed
GUEST, unregistred user!
利用ADSI接口已经建立了NT域用户,可是不知道如何在Exchange Server里建立一个邮箱.祈求各位大侠给点提示(Delphi,C++Builder,VC均可)谢谢
 
老兄:

我最近在建立办公环境,想用Exchage Server,没想到以前买的
Exchage Server5.5都是英文版本的 :(

老兄用的是那个版本,那里有中文版的?谢谢!

我去帮你试一下,如何添加一个邮箱

 
IE4.0/5.0是否提供此功能。
 
我用的是5.5英文版。中文版我也在找。
IE 应该没有这种功能吧。安装了Exchange Server 和 它的SDK,我才能使用ADSI.
网上有很多例子,可是都是 VB 和 ASP的。用 C 来写,又时常出错。惭愧惭愧
 
VB肯定也是用的api,况且,有了例子应该好该呀

我以前的一家公司里面就是用的Exchange server中文版本的 :(

 
我也在做此类程序,有结果了告诉我。
 
ADSI 的局限性
ADSI不能操作包含了用户对确定对象访问权限的安全信息的访问控制列表(ACLs)。也不能获得Windows NT的安全性标识(SID),用户的帐户名用二进制表示,因而不能设置必要的位来为用户创建权限。因此开发者不能和ADSI创建具有全功能的Mailbox对象, 这是因为邮箱对象在Assoc-NT-Account 属性中需要 NT帐户的 SID,如同在NT-Security-Descriptor 属性中邮箱对象需要适当的安全权限一样。可操作ACLs 的能力寄希望于下一个版本

msdn里这段话的意思,好像就是说ADSI不可以创建邮箱对象,
看来老兄只有另想办法了,如果已经解决,请告知,我很感兴趣.

 
在ADSI提供的SDK中已经有个现成完整的例子是可以生成NT用户和Exchange Server邮箱,经测试完全没问题。可是它是用VB写的。把它翻译成C或DELPHI,功力不够。程序如下:
Public Function Create_NT_Account(strDomain As String, _
strAdmin As String, _
strPassword As String, _
UserName As String, _
FullName As String, _
NTServer As String _
) As Boolean

Dim oNS As IADsOpenDSObject
Dim User As IADsUser
Dim Domain As IADsDomain

On Error GoTo Create_NT_Account_Error

Create_NT_Account = False

If (strPassword = "") Then
strPassword = ""
End If

Set oNS = GetObject("WinNT:")
Set Domain = oNS.OpenDSObject("WinNT://" & strDomain, strDomain & "/" & strAdmin, strPassword, 0)

Set User = Domain.Create("User", UserName)
With User
.Description = "User created by ADSI"
.FullName = FullName
.HomeDirectory = "//" & NTServer & "/" & UserName
.LoginScript = LOGON_CMD
.SetInfo
' First password = username
.SetPassword UserName
End With

Debug.Print "Successfully created NT Account for user " & UserName
Create_NT_Account = True
Exit Function

Create_NT_Account_Error:

Debug.Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred creating NT account for user " & UserName

End Function
Public Function Create_Exchange_MailBox( _
IsRemote As Boolean, _
strServer As String, _
strDomain As String, _
strAdmin As String, _
strPassword As String, _
UserName As String, _
EMailAddress As String, _
strFirstName As String, _
strLastName As String, _
ExchangeServer As String, _
ExchangeSite As String, _
ExchangeOrganization As String _
) As Boolean

Dim Container As IADsContainer
Dim strRecipContainer As String
Dim Mailbox As IADs
Dim rbSID(1024) As Byte
Dim OtherMailBox() As Variant
Dim sSelfSD() As Byte
Dim encodedSD() As Byte
Dim I As Integer

Dim oNS As IADsOpenDSObject

On Error GoTo Create_Exchange_MailBox_Error

Create_Exchange_MailBox = False

If (strPassword = "") Then
strPassword = ""
End If

' Recipients container for this server
strRecipContainer = "LDAP://" & ExchangeServer & _
"/CN=Recipients,OU=" & ExchangeSite & _
",O=" & ExchangeOrganization
Set oNS = GetObject("LDAP:")
Set Container = oNS.OpenDSObject(strRecipContainer, "cn=" & strAdmin & ",dc=" & strDomain, strPassword, 0)

' This creates both mailboxes or remote dir entries
If IsRemote Then
Set Mailbox = Container.Create("Remote-Address", "CN=" & UserName)
Mailbox.Put "Target-Address", EMailAddress
Else
Set Mailbox = Container.Create("OrganizationalPerson", "CN=" & UserName)
Mailbox.Put "MailPreferenceOption", 0
End If

With Mailbox
.SetInfo

' As an example two other addresses
ReDim OtherMailBox(1)
OtherMailBox(0) = "MS$" & ExchangeOrganization & _
"/" & ExchangeSite & _
"/" & UserName

OtherMailBox(1) = "CCMAIL$" & UserName & _
" at " & ExchangeSite

If Not (IsRemote) Then
' Get the SID of the previously created NT user
Get_Exchange_Sid strDomain, UserName, rbSID
.Put "Assoc-NT-Account", rbSID
' This line also initialize the "Home Server" parameter of the Exchange admin
.Put "Home-MTA", "cn=Microsoft MTA,cn=" & ExchangeServer & ",cn=Servers,cn=Configuration,ou=" & ExchangeSite & ", o = " & ExchangeOrganization
.Put "Home-MDB", "cn=Microsoft Private MDB,cn=" & ExchangeServer & ",cn=Servers,cn=Configuration,ou=" & ExchangeSite & ",o=" & ExchangeOrganization
.Put "Submission-Cont-Length", OUTGOING_MESSAGE_LIMIT
.Put "MDB-Use-Defaults", False
.Put "MDB-Storage-Quota", WARNING_STORAGE_LIMIT
.Put "MDB-Over-Quota-Limit", SEND_STORAGE_LIMIT
.Put "MAPI-Recipient", True

' Security descriptor
' The rights choosen make a normal user role
' The other user is optionnal, delegate for ex.

Call MakeSelfSD(sSelfSD, _
strServer, _
strDomain, _
UserName, _
UserName, _
RIGHT_MAILBOX_OWNER + RIGHT_SEND_AS + _
RIGHT_MODIFY_USER_ATTRIBUTES _
)

ReDim encodedSD(2 * UBound(sSelfSD) + 1)
For I = 0 To UBound(sSelfSD) - 1
encodedSD(2 * I) = AscB(Hex$(sSelfSD(I) / &H10))
encodedSD(2 * I + 1) = AscB(Hex$(sSelfSD(I) Mod &H10))
Next I

.Put "NT-Security-Descriptor", encodedSD
Else

ReDim Preserve OtherMailBox(2)
OtherMailBox(2) = EMailAddress
.Put "MAPI-Recipient", False
End If

' Usng PutEx for array properties
.PutEx ADS_PROPERTY_UPDATE, "otherMailBox", OtherMailBox

.Put "Deliv-Cont-Length", INCOMING_MESSAGE_LIMIT
' i : initials
.Put "TextEncodedORaddress", "c=" & COUNTRY & _
";a= " & _
";p=" & ExchangeOrganization & _
";o=" & ExchangeSite & _
";s=" & strLastName & _
";g=" & strFirstName & _
";i=" & Mid(strFirstName, 1, 1) & Mid(strLastName, 1, 1) & ";"

.Put "rfc822MailBox", UserName & "@" & ExchangeSite & "." & ExchangeOrganization & ".com"
.Put "Replication-Sensitivity", REPLICATION_SENSITIVITY
.Put "uid", UserName
.Put "name", UserName

.Put "GivenName", strFirstName
.Put "Sn", strLastName
.Put "Cn", strFirstName & " " & strLastName
.Put "Initials", Mid(strFirstName, 1, 1) & Mid(strLastName, 1, 1)

' Any of these fields are simply descriptive and optional, not included in
' this sample and there are many other fields in the mailbox
.Put "Mail", EMailAddress
'If 0 < Len(Direction) Then .Put "Department", Direction
'If 0 < Len(FaxNumber) Then .Put "FacsimileTelephoneNumber", FaxNumber
'If 0 < Len(City) Then .Put "l", City
'If 0 < Len(Address) Then .Put "PostalAddress", Address
'If 0 < Len(PostalCode) Then .Put "PostalCode", PostalCode
'If 0 < Len(Banque) Then .Put "Company", Banque
'If 0 < Len(PhoneNumber) Then .Put "TelephoneNumber", PhoneNumber
'If 0 < Len(Title) Then .Put "Title", Title
'If 0 < Len(AP1) Then .Put "Extension-Attribute-1", AP1
'If 0 < Len(Manager) Then .Put "Extension-Attribute-2", Manager
'If 0 < Len(Agence) Then .Put "Extension-Attribute-3", Agence
'If 0 < Len(Groupe) Then .Put "Extension-Attribute-4", Groupe
'If 0 < Len(Secteur) Then .Put "Extension-Attribute-5", Secteur
'If 0 < Len(Region) Then .Put "Extension-Attribute-6", Region
'If 0 < Len(GroupeBanque) Then .Put "Extension-Attribute-7", GroupeBanque
'If 0 < Len(AP7) Then .Put "Extension-Attribute-8", AP7
'If 0 < Len(AP8) Then .Put "Extension-Attribute-9", AP8
.SetInfo
End With

Debug.Print "Successfully created mailbox for user " & UserName
Create_Exchange_MailBox = True
Exit Function

Create_Exchange_MailBox_Error:

Debug.Print "Error 0x" & CStr(Hex(Err.Number)) & " occurred creating Mailbox for user " & UserName

End Function
 

杨兄, 我以前增加NT域用户, 都是调用NETUSER命令,

你能用ADSI真是太好了, 能不能MAIL一份你的源程序给我,

我也要研究ADSI.

MY EMAILADDRESS: FATE@21CN.COM , THANKS!
 
我用 C++BUILDER 写了一个测试程序,生成 NT用户没有问题,只是没有做加入密码这一项.可是一直无法做到生成 Exchange Server 邮箱。望各路大虾救我.
程序如下:
#pragma hdrstop
#include <condefs.h>
#include <activeds.h> //在ADSI的SDK里附带的
#include <stdio.h>
#include <ole2.h>

HRESULT CreateUsers();
//---------------------------------------------------------------------------

#pragma argsused
int main(int argc, char* argv[])
{
HRESULT hr;


CoInitialize(NULL);

hr=CreateUsers();

if SUCCEEDED(hr) {
CreateMailbox3();
}
CoUninitialize();
return 0;
}

HRESULT CreateUsers()
{
HRESULT hr;
IADsContainer *pCont = NULL;
IDispatch *pDisp=NULL;

///////////////////////////////////////////////////
// 使用 IADsContainer::Create 建立用户
////////////////////////////////////////////////////

hr = ADsGetObject( L"WinNT://HXSERVER",IID_IADsContainer, (void**) &pCont );
if (!SUCCEEDED(hr) )
{
return 0;
}

IADs *pADs=NULL;
hr = pCont->Create(L"user", L"123", &pDisp);//123 是用户名
pCont->Release();

if( !SUCCEEDED(hr) )
{
return 0;
}

hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs );
pDisp->Release();

if ( !SUCCEEDED(hr) )
{
return 0;
}

pADs->SetInfo(); // 提交
pADs->Release(); // 更新
}

 
创建NT用户我也能做到,但EXCHANGE的则,不知哪位好心的大虾能把上面的VB程序译出来(我不懂VB)
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
937
SUNSTONE的Delphi笔记
S
后退
顶部