0 votes
by (160 points)

Can I use Secure Mail to connect to an Exchange server with network credentials (username & password), and then find out what the email address of that authenticated user is?

Applies to: Rebex Secure Mail

1 Answer

+1 vote
by (64.5k points)
selected by
 
Best answer

The suggested solution is to use OAuth authentication, then you can get the email address from the OAuth token.

In case of authenticating using network credentials, the EWS protocol offers the ResolveNames() method. It should be suitable to achieve your needs. It can be used like this:

string username = "YOUR_USERNAME_HERE";
string email = "";

var names = client.ResolveNames(username);
foreach (var n in names)
{
    if (username.Equals(n.Name, StringComparison.OrdinalIgnoreCase) && !string.IsNullOrWhiteSpace(n.EmailAddress))
    {
        email = n.EmailAddress;
        break;
    }
}

Console.WriteLine("{0}: {1}", username, email);

If this approach does not work for you, investigate complete server response (the names collection) and maybe you spot something useful for you.

...