DanC
DanC

Reputation: 8805

Using Exchange EWS SOAP, how can I get the email address for a given usename

I am integrating the login of a NodeJS app to the company's Active Directory using the Exchange Web Services endpoint. This way I can validate if the provided credentials (username and password) match with the Active Directory user's credentials.

So far I was able to successfully validate if a username/password pair is valid. What I couldn't find a solution for is getting the email address given a username.

I cannot query the Active Directory directly using LDAP since the NodeJS app will be hosted outside the company's network. An available option is to use the Exchange Web Services (2010) endpoint.

I am currently doing a ResolveNames operation http://msdn.microsoft.com/en-us/library/exchange/aa563518(v=exchg.150).aspx

The problem is that doing a Resolvenames with the username as the UnresolvedEntry value will return several Resolutions, for example if a username is john and there are also other johns in the directory, the Resolvenames query will return those as well.

I am looking for a way to get unambiguously the email address using EWS for a username (which corresponds to the valid credentials being used to query the EWS SOAP service).

Upvotes: 1

Views: 981

Answers (1)

Devarsh
Devarsh

Reputation: 126

Have never came across a direct method that gives email-address of logged in user, but you can do simple hack by creating a PostItem and then getting email-address by its PostItem.getFrom() method, something like :

    PostItem postItem = new PostItem( service );
    postItem.setBody( MessageBody.getMessageBodyFromText("Test for email-address " ) );
    postItem.save();

    postItem = PostItem.bind( service , postItem.getId() ); 
    System.out.println( postItem.getFrom() );

    postItem.delete( DeleteMode.HardDelete );

Upvotes: 1

Related Questions