Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get logged on user's SMTP address via EWS?

I have a client app written using EWS Managed API 1.1. Here's the situation:

  • The client does not run on a computer within the same domain as the Exchange Server.
  • I have the username and password of a user, but not their email address.
  • There's no commonality between username (e.g. ABC123\001234) and email address (e.g. [email protected]).

I can connect to EWS just fine, send messages, etc.

However my software needs to discover the authenticated user's email address, and for various requirements reasons can't just ask the user to provide it.

I assumed I'd be able to get such a simple detail back from the web service, but I'm stumped!

Is this possible for both 2007 and 2010?

Thanks!

like image 876
Chris Wood Avatar asked May 21 '11 10:05

Chris Wood


People also ask

How to check primary SMTP address?

Sign in to your Exchange admin center. Go to recipients > mailboxes and check the email address shown in the EMAIL ADDRESS column. This is the primary SMTP address (Fig. 2.).

What does EWS URL mean?

Our integration with Exchange/Outlook Calendar requires the address of your Exchange server, called EWS URL (Exchange Web Services URL). This is usually auto-detected using your email address, but sometimes the auto-detection may fail. A common cause of failure is when your Exchange admin disabled auto-detection.

What is Office 365 EWS URL?

The URL of Exchange Web Services for the mailbox is the URL: https://MAIL-SERVER/EWS/Exchange.asmx.


1 Answers

You may be able to do it using ExchangeService.ResolveName. I tried it with the following EWS Managed API code example on Exchange 2007 and it worked like a charm:

var service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.Url = new Uri("https://serv/EWS/exchange.asmx");
service.Credentials = new NetworkCredential("001234", "PasswordForUser001234", "Domain");

ServicePointManager.ServerCertificateValidationCallback = (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) =>
    {
        return true;
    };

var resolvedNames = service.ResolveName("001234");
foreach (var resolvedName in resolvedNames)
{
    Console.WriteLine(resolvedName.Mailbox.Address);
}
like image 89
Jakob Christensen Avatar answered Jan 04 '23 07:01

Jakob Christensen