Microsoft Exchange: How To Resolve A Distinguished Name

拈花ヽ惹草 提交于 2019-12-02 04:25:31

问题


How can i resolve this:

/O=CHEESE/OU=FIRST ADMINISTRATIVE GROUP/CN=RECIPIENTS/CN=LHALA1

to an email address? Do i have to use Exchange Web Services?


回答1:


I'm assuming this is the legacyExchangeDN Attribute.

Try something like this:

string dn = "/O=CHEESE/OU=FIRST ADMINISTRATIVE GROUP/" +
        "CN=RECIPIENTS/CN=LHALA1";
string MailAddress=string.Empty;
string user = string.Empty;

using (DirectorySearcher ds = new DirectorySearcher())
{
    ds.Filter = string.Format("(&(ObjectClass=User)(legacyExchangeDN={0}))", 
            dn);
    SearchResultCollection src = ds.FindAll();
    if (src.Count > 1)
    {
        //Oops too many!
    }
    else
    {
        user = src[0].Properties["samAccountName"][0].ToString();
        MailAddress = src[0].Properties["Mail"][0].ToString();
    }
}



回答2:


If you can do an LDAP search of the directory you can retrieve the entry for that user and then the default email address will be in the mail: attribute

If it is a mailbox-enabled Exchange user there will also be addresses in the proxyAddresses: attribute, of a contact or a non-mailbox mail-enabled user there will be remote addresses in the targetAddress: attribute



来源:https://stackoverflow.com/questions/17168066/microsoft-exchange-how-to-resolve-a-distinguished-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!