Print This Post

5-Minute-Snack: Accessing Exchange Mails, Contacts, Calendars and everything else with Delphi Rio

We all remember the days when we used ActiveX to access content from Microsoft products. Then, Delphi allowed us to import TLB files and everything became much easier. Still, you needed to have these tools on your machine as well as the app. Today, I would like to introduce you to the CData Exchange data controls for Delphi. They allow access not only to “regular” Exchange servers, but also to any Office 365 account. This makes this data provider very powerful. If you allow me a personal remark: It is the most powerful and efficient data provider in the set.

The data provider is very easy to use as the data in Exchange has a database-feeling associated with it. Thus, representing an Exchange server as datasets just feels natural. 
Here is a link to the data provider in case you want to play along while reading this. The component vendor offers a trial.

Other data providers in the CData toolset feel a bit strange when accessing DropBox content using database queries, for example. I can refer the light-weighted, brand new FNC Cloud Pack from TMS instead:

Back to the Exchange Data provider:

  1. Create a new Windows VCL Forms Application.
  2. Drop a TFDConnection on the form.
  3. Double-click the connection and set its Driver ID to “CDataExchange”. The connection dialog will now provide all the parameters you need to connect to any Exchange server.
  4. If you want to connect to an Office 365 Exchange Server, you need to set the server to https://outlook.office365.com/EWS/Exchange.asmx
  5. Mind that the data provider is designed to connect to this kind of server by default. In order t connect to another server you need to change the Platform parameter. If you want to connect to Exchange 2013 SP 1, you need to set Platform to “Exchange_2013_SP1”, for example.
  6. Do not forget to set User and Password next. If you connect to your own Exchange server, you will most certainly also need to change the Authentication Scheme to something different than BASIC. 
  7. Click “Test” to check if you can connect. If you get the message “Connection established successfully.” after clicking “OK’ in the Login Dialog, you are ready to go. Otherwise, you need to make changes to the connection parameters.

That’s it!

Let’s get all the contacts with their name and email address from the contacts. If you add a connection like this to your data explorer, you can explore the server easily and learn how to build queries. The documentation from CData is also exhaustive.

  1. Add a FDQuery and link it to the connection.
  2. Set “LoginPrompt” of the connection to “False”.
  3. Double-click the query and enter:

The query will list company name, first name, last name and the first email address of all contacts. 

Could it be any easier to access content from Microsoft Exchange? In my next video, I will show you how to implement a web service that delivers Exchange data. This will allow the Exchange Data Provider to be used in web applications, for example.

Tags: ,

Partnerships



Top