I wonder if I can use c# and DirectoryService to manipulate an Exchange 5.5 mailbox account..
I did some test, and I can read the mailbox information (from exchange 55). But I cannot create an new mailbox and I cannot search it..
here are my code,, can anyone help? thanks..
================================================== ====
// here: the Ldappath, I put in is "LDAP://exchangeservername"
// mailboxdirname is a mailbox directory name
// I cannot find anything, even I put into a existing mailbox
// directory name,, don't know what's going on.
public int SearchExchange(string LDAPPath, string mailboxDirectoryName)
{
DirectoryEntry searchroot = new DirectoryEntry(LDAPPath);
DirectorySearcher ds = new DirectorySearcher(searchroot);
ds.SearchScope = SearchScope.Subtree;
ds.Filter = "(&(objectClass=person)(cn=" + mailboxDirectoryName + "))";
SearchResultCollection results = ds.FindAll();
return results.Count;
// switch (results.Count)
// {
// case 0: //cannot find any account
// return null;
// case 1: //find exactly the entry
// return results[0].GetDirectoryEntry();
// default: // error occured
// throw(new ApplicationException("An error occurred in Exchange. Duplicate accounts found."));
// }
}
// for saving, I always get either "conflict violation"
// or "properties not found.. wired..
public void Save()
{
try
{
DirectoryEntry mailboxContainer = new DirectoryEntry("LDAP://exchangeservername/o=exchangeOrg/ou=exchangesite/cn=Recipients","administrator","password");
DirectoryEntry mailbox = mailboxContainer.Children.Add("cn=george 1234","organizationalPerson");
mailbox.Properties["mailPreferenceOption"].Value = "0";
mailbox.Properties["rdn"].Value = "huang123rdn";
//mailbox.Properties["givenName"].Value = "george";
mailbox.Properties["sn"].Value = "huang";
mailbox.Properties["uid"].Value = "huang1234";
//mailbox.Properties["mail"].Value = "
[email protected]";
//mailbox.Properties["MAPI-Recipient"].Value = (bool)true;
mailbox.Properties["rfc822Mailbox"].Value = "
[email protected]";
// ' Commit the property cache to the directory service
mailbox.CommitChanges();
}
catch(Exception ex)
{
throw ex;
}