Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top