How to tips and tricks for Microsoft Visual Studio .net

Tuesday, May 5, 2015

Microsoft Exchange Web Services – First things first



Microsoft Exchange Web Services (EWS) allows you to manage your Microsoft Exchange account using built in web services on the Exchange server.
Some of the things EWS allows you to do:

  1. Read mail in any of the folders that your account has access to
  2. Send e-mails from your account
  3. Manage appointments
  4. Move e-mails from one folder to another
The first thing I can recommend is to download and install the Microsoft Exchange Web Services API.

Version 2.2 of the API can be found here:
https://www.microsoft.com/en-us/download/details.aspx?id=42951

Use the following link to find out where your Exchange Web Services are installed, so that you can use the URL as the _service.Url in the code below:
http://blogs.msdn.com/b/deva/archive/2011/12/02/how-to-get-the-ews-endpoint-url-from-outlook-2007-2010.aspx

Once you have the API installed, and you know what the services URL is, you can start a new Visual Studio project, and add Microsoft.Exchange.WebServices.dll as a reference to the project.

In my installation's case it is located in C:\Program Files\Microsoft\Exchange\Web Services\2.2.


You are now ready to get going:

      Private _service As Microsoft.Exchange.WebServices.Data.ExchangeService = New Microsoft.Exchange.WebServices.Data.ExchangeService(Microsoft.Exchange.WebServices.Data.ExchangeVersion.Exchange2010_SP1)  
      Private _serviceCredentials = New Microsoft.Exchange.WebServices.Data.WebCredentials("exchangeUserId", "exchangePassword", "optionalDomainName")  
   
      Private Sub Initiate_EWS_Service()  
           _service.Credentials = _serviceCredentials  
           _service.Url = New Uri("https://exchangeWebServiceURL")  
      End Sub  
   
      Initiate_EWS_Service()  
   

This little bit of code will connect to your Exchange Server and authenticate your supplied credentials. You can use _service to interact with the exchange server account, and perform the functions I mentioned at the beginning of this post.

More posts about Exchange Web Services will follow.


Please let me know if you found this info helpful.

No comments:

Post a Comment