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();