2

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?

Terry Gardner
  • 10,957
  • 2
  • 28
  • 38
rupertmulrenan
  • 355
  • 1
  • 3
  • 13

2 Answers2

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();
    }
}
almightyGOSU
  • 3,731
  • 6
  • 31
  • 41
Daro
  • 1,990
  • 2
  • 16
  • 22
0

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

Ken
  • 51
  • 1
  • 1