我正在尝试自动化为 AD 用户创建 Exchange 邮箱的过程,但遇到了问题。调用 CreateMailbox 方法时,我收到错误“错误 HRESULT E_FAIL 已从对 COM 组件的调用中返回”。我已经安装并引用了 Exchange 管理工具,并且正在使用模拟来获取权限。
这是代码:
ActiveDs.IADsUser adUser = (ActiveDs.IADsUser)user.NativeObject;
adUser.AccountDisabled = !Active;
user.CommitChanges();
//Set Password
user.Invoke("SetPassword", Password);
user.CommitChanges();
//Create Mailbox
IMailboxStore mailbox;
mailbox = (IMailboxStore)adUser;
mailbox.CreateMailbox("LDAP://CN=StandardUsers,CN=StandardUsers,CN=InformationStore,CN=xxxxx," +
"CN=Servers,CN=First Administrative Group,CN=Administrative Groups," +
"CN=xxxxx Main,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=xxxxx,DC=com");
user.CommitChanges();