You can also leverage CDOEXM from Visual Studio .NET by using COM interoperability. The following code shows how to create a new mailbox by using the DirectoryEntry class in the .NET Framework for ADSI and by using CDOEXM:
using System; //You need to add references to CDOEXM and System.DirectoryServices for this //to work using CDOEXM; using System.DirectoryServices; namespace MBSample { class Class1 { [STAThread] static void Main(string[] args) { string defaultDC = "DC=domain,DC=com"; string alias = "thomriz"; string fullName = "Tom Rizzo"; string password = "password1234"; string domainName = "domain.com"; string homeMDB = "CN=Mailbox Store (Server),CN= Storage Group," + "CN=InformationStore,CN= Server,CN=Servers," + "CN=Your Administrative Group,CN=Administrative Groups," + "CN=Your Org,CN=Microsoft Exchange,CN=Services," + "CN=Configuration,DC=domain,DC=Com"; DirectoryEntry container, user; CDOEXM.IMailboxStore mailbox; //Create a new user in the "users" container //Set the sAMAccountName and the password container = new DirectoryEntry("LDAP://CN=users," + defaultDC); user = container.Children.Add("CN=" + fullName, "user"); user.Properties["sAMAccountName"].Add(alias); user.CommitChanges(); user.Invoke("SetPassword", new object[]{password}); //Enable the new user: //ADS_UF_NORMAL_ACCOUNT = 0x200 user.Properties["userAccountControl"].Value = 0x200; user.CommitChanges(); //Obtain IMailboxStore interface //Create the mailbox //commit the changes mailbox = (IMailboxStore)user.NativeObject; mailbox.CreateMailbox(homeMDB); user.CommitChanges(); return; } } }