开发者

Find Primary SMTP address using Secondary E-mail address With EWS

Using Exchange Web Services on Exchange Server 201开发者_如何学Go0, I need to look up a user's primary SMTP address using a secondary e-mail address.

I'm trying to use ExchangeService.ResolveName(emailAddress). But, ResolveName() does not seem to match secondary e-mail addresses to primary ones. If I pass in the user's first and last name, then it finds the primary address. But, I need to be able to match using secondary e-mails.

Am I doing something wrong? How can I match a secondary address to a primary one?

Thank you,

Tedderz


See http://www.infinitec.de/post/2009/04/13/Resolving-the-primary-email-address-with-Exchange-WebServices-ResolveNames-operation.aspx.


You need to call ResolveName with a string of the form smtp:someone@example.com. I'm not sure if ResolveName will ever return anything else than the primary SMTP address when called like this. But I checked the mailbox type just in case. The following code seems to work for me.

private string GetPrimarySmtpAddress(ExchangeService service, string email)
{
    foreach (NameResolution resolution in service.ResolveName("smtp:" + email))
    {
        if (resolution.Mailbox.MailboxType == MailboxType.Mailbox)
        {
            return resolution.Mailbox.Address;
        }
    }
    return "";
}

Add error handling as needed of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜