简体   繁体   中英

get email address from username outlook java

I need to get the email address corresponding to a particular Username in outlook through JAVA. I have tried digging into the microsoft exchange webservices API, but couldnt find anything useful. The only faint hope i had was with the , resolveNames() method, but that proved to be a dead end. Does anyone have an idea on how to go about it?

what i basically need is this :

username : "abcxqz"

when we do a Ctrl + k on outlook, it gives the corresponding contact or email address.

i need to simulate the same functionality in code( JAVA ) . Any pointers or links to API's that could help me achieve this would be greatly appreciated. Cheers

What code exactly do you use? Could you be more specific?

You can use the ExchangeService.ResolveName EWS Managed API method or the ResolveNames EWS operation to return a list of potential matches for a selection of text, such as part of a last name. The returned items can be public user mailboxes, distribution groups, and contacts.

// Resolve the ambiguous name "dan".
NameResolutionCollection resolvedNames = service.ResolveName("dan");
// Output the list of candidates.
foreach (NameResolution nameRes in resolvedNames)
{
   Console.WriteLine("Contact name: " + nameRes.Mailbox.Name);
   Console.WriteLine("Contact e-mail address: " + nameRes.Mailbox.Address);
   Console.WriteLine("Mailbox type: " + nameRes.Mailbox.MailboxType);
}

See How to: Resolve ambiguous names by using EWS in Exchange 2013 for more information.

public void getEmailId() throws Exception {
    init();
    NameResolutionCollection nameResults = exchangeService.resolveName("royran");
    Map<String, String> results = new TreeMap<String, String>();
    for (NameResolution name : nameResults) {
        String contactName = name.getMailbox().getName();
        String emailAddress = name.getMailbox().getAddress();
        results.put(contactName, emailAddress);
    }

    for (Map.Entry<String, String> entry : results.entrySet())
    { 
        System.out.println(entry.getKey() + "/" + entry.getValue());
    } 
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM