adding a mail contact into AD
I am looking for a bit of guidence on how to create mail contacts in AD. This is a follow on question from SO Q#1861336.
What I am trying to do is add a load of contact objects into an OU in Active Directory. I've been using the examples on CodeProject, however they only show how to make new user etc.
How do I create a contact using c#? Is it similar to creating a new user but with different LDAP type attributes?
My plan is to then run the enable-mailcontact cmdlet powershell script to enable Exchange 2010 to see the contac开发者_JS百科t in the GAL.
As you can see by my questions I don't usually deal with c# or Active Directory so any help/pointers would be really useful before I start playing with this loaded gun.
Thanks,
Grant
it is similar to creating user
just us "contact" instead of "user" as an object
here is a dirty code (not tested)
public string CreateContact(string ldapPath, string userName,
string userEmail)
{
string oGUID = string.Empty;
try
{
string connectionPrefix = "LDAP://" + ldapPath;
DirectoryEntry dirEntry = new DirectoryEntry(connectionPrefix);
DirectoryEntry newUser = dirEntry.Children.Add
("CN=" + userName, "contact");
newUser.Properties["DisplayName"].Value = userName;
//important attributs are
newUser.Properties["targetAddress"].Value = "SMTP:" + userEmail;
newUser.Properties["mailNickname"].Value = userName;
// I'm still trying to figureout what shoud I use here!
newUser.Properties["showInAddressBook"].Value = ???;
newUser.CommitChanges();
oGUID = newUser.Guid.ToString();
dirEntry.Close();
newUser.Close();
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
//DoSomethingwith --> E.Message.ToString();
//MessageBox.Show(E.Message);
}
return oGUID;
}
hope it helps you
精彩评论