gpt4 book ai didi

c# - 将邮件联系人添加到 AD

转载 作者:行者123 更新时间:2023-11-30 21:23:09 30 4
gpt4 key购买 nike

我正在寻找有关如何在 AD 中创建邮件联系人的指导。这是来自 SO Q#1861336 的后续问题.

我想要做的是将大量联系人对象添加到 Active Directory 中的 OU 中。我一直在使用 CodeProject 上的示例,但是他们只展示了如何创建新用户等。

如何使用 C# 创建联系人?它是否类似于创建新用户但具有不同的 LDAP 类型属性?

我的计划是然后运行 ​​enable-mailcontact cmdlet powershell 脚本以使 Exchange 2010 能够在 GAL 中查看联系人。

正如您从我的问题中看到的那样,我通常不处理 C# 或 Active Directory,因此在我开始玩这把上膛的枪之前,任何帮助/指针都会非常有用。

谢谢,

授予

最佳答案

类似于创建用户

只是我们“联系”而不是“用户”作为对象

这里是脏代码(未测试)

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;
}

希望对你有帮助

关于c# - 将邮件联系人添加到 AD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1945483/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com