I am trying to automate the process of creating an Exchange Mailbox for AD users and am running into an issue. When calling the CreateMailbox method I am receiving the error "Error HRESULT E_FAIL has been returned from a call to a COM component". I have installed and referenced the Exchange Management Tools and am using impersonation for permissions.
Here is the code:
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();
-
My original response was kinda wack; I totally misread the code. What you have is similar to what we had working in production back during Exch 2003. We called the code from a web service that ran as an account that had admin privileges in AD and Exchange.
Anyhow, this is what MSDN is saying now link:
Important Because of issues with multiple-hop authentication and unexpected results observed in multithreaded runtime environments, Microsoft® does not support using CDO for Exchange Management (CDOEXM) in Microsoft ASP.NET pages, ASP Web pages or in Web services. To create Web-based Microsoft Exchange management applications that use CDOEXM functionality, Microsoft recommends wrapping CDOEXM in a Distributed Component Object Model (DCOM) package and calling that package from your application.
Matt : adUser is an IADsUser object, user is the DirectoryEntrybarneytron : From what I understand, DirectoryEntry is a .NET wrapper around ADSI object, in this case, the IADsUser. And according to MSDN, the NativeObject property of DirectoryEntry: "gets the native Active Directory Service Interfaces (ADSI) object."Matt : That didn't work...Thanks for your help.barneytron : Hey, you're right Matt! I misread the snippet from the question. Sorry...
0 comments:
Post a Comment