Read appointments using exchange web service (EWS)

Posted by thomas.rothlisberger on 25-Jun-2014 22:24

I am trying to read appointments in outlook using exchange web service. Has anybody done that and if yes, would you be so kind and share the code. thanks

Posted by tbergman on 26-Jun-2014 20:42

I’m not certain for appointments but for mail items the code in question would look something like.
 
DEF VAR myResults AS "FindItemsResults<Item>".
def var email as EmailMessage.
myResults = service:FindItems(WellKnownFolderName:Inbox,sFilter,myView).
email = cast(myResults:Items[0],EmailMessage).
 
Tom Bergman
Tom.Bergman@WoltersKluwer.com
 
[collapse]
From: thomas.rothlisberger [mailto:bounce-thomasrothlisberger@community.progress.com]
Sent: Thursday, June 26, 2014 8:06 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Read appointments using exchange web service (EWS)
 
Reply by thomas.rothlisberger

Hi

I am using OE11.3 on windows Server 2008.

I have put together the following code but I can't figure out what sort of object I need in the find command (= calendar.findAppointments(cview). Using cappt is giving me incompatible data type. I tried various ones but can't get it to work.

Below is my code example:

USING System.*.

USING Microsoft.Exchange.WebServices.Data.*.

USING System.Net.Security.*.

USING System.Security.Cryptography.X509Certificates.*.

DEFINE VARIABLE service   AS ExchangeService.  

DEFINE VARIABLE ApptStart AS DATETIME.

DEFINE VARIABLE ApptEnd   AS DATETIME.

apptStart = NOW.

apptEnd = NOW + 3600000.

service = NEW ExchangeService(ExchangeVersion:Exchange2013) .

service:credentials = NEW WebCredentials("myemailaddress", "").

service:AutodiscoverUrl("myurl").

def var cView as Microsoft.Exchange.WebServices.Data.CalendarView.

def var calendar as Microsoft.Exchange.WebServices.Data.CalendarFolder.

def var cappt as Microsoft.Exchange.WebServices.Data.Appointment.

  calendar = CalendarFolder:Bind(service, WellKnownFolderName:Calendar, new PropertySet()).

  cView = new CalendarView(apptStart, apptEnd, 5).

  cappt = calendar:FindAppointments(cView).

  message cappt:Subject.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

All Replies

Posted by oedev on 26-Jun-2014 02:54

Hi,

What version of Openedge are you working with ? When I've previously looked at this, I was going to use a .NET Framework API, to hide some of the complexity.

I've used an evaluation version from www.independentsoft.de/index.html which has worked great. For example, to read appointments from today onwards using their C# example looks like this;

using System;
using System.Net;
using Independentsoft.Exchange;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            NetworkCredential credential = new NetworkCredential("username", "password");
            Service service = new Service("https://myserver/ews/Exchange.asmx", credential);

            try
            {
                IsGreaterThanOrEqualTo restriction1 = new IsGreaterThanOrEqualTo(AppointmentPropertyPath.StartTime, DateTime.Today);
                IsLessThanOrEqualTo restriction2 = new IsLessThanOrEqualTo(AppointmentPropertyPath.EndTime, DateTime.Today.AddDays(1));
                And restriction3 = new And(restriction1, restriction2);

                FindItemResponse response = service.FindItem(StandardFolder.Calendar, AppointmentPropertyPath.AllPropertyPaths, restriction3);

                for (int i = 0; i < response.Items.Count; i++)
                {
                    if (response.Items[i] is Appointment)
                    {
                        Appointment appointment = (Appointment)response.Items[i];

                        Console.WriteLine("Subject = " + appointment.Subject);
                        Console.WriteLine("StartTime = " + appointment.StartTime);
                        Console.WriteLine("EndTime = " + appointment.EndTime);
                        Console.WriteLine("Body Preview = " + appointment.BodyPlainText);
                        Console.WriteLine("----------------------------------------------------------------");
                    }
                }

                Console.Read();
            }
            catch (ServiceRequestException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.WriteLine("Error: " + ex.XmlMessage);
                Console.Read();
            }
            catch (WebException ex)
            {
                Console.WriteLine("Error: " + ex.Message);
                Console.Read();
            }
        }
    }
}


Not linked to the company (!), but seems competitively priced at 299 euros for a developer license.

HTH.

Posted by cverbiest on 26-Jun-2014 02:58

There are a number of very interesting blog posts on www.thesoftwaregorilla.com/.../exchange-ews

Posted by thomas.rothlisberger on 26-Jun-2014 19:05

Hi

I am using OE11.3 on windows Server 2008.

I have put together the following code but I can't figure out what sort of object I need in the find command (= calendar.findAppointments(cview). Using cappt is giving me incompatible data type. I tried various ones but can't get it to work.

Below is my code example:

USING System.*.

USING Microsoft.Exchange.WebServices.Data.*.

USING System.Net.Security.*.

USING System.Security.Cryptography.X509Certificates.*.

DEFINE VARIABLE service   AS ExchangeService.  

DEFINE VARIABLE ApptStart AS DATETIME.

DEFINE VARIABLE ApptEnd   AS DATETIME.

apptStart = NOW.

apptEnd = NOW + 3600000.

service = NEW ExchangeService(ExchangeVersion:Exchange2013) .

service:credentials = NEW WebCredentials("myemailaddress", "").

service:AutodiscoverUrl("myurl").

def var cView as Microsoft.Exchange.WebServices.Data.CalendarView.

def var calendar as Microsoft.Exchange.WebServices.Data.CalendarFolder.

def var cappt as Microsoft.Exchange.WebServices.Data.Appointment.

  calendar = CalendarFolder:Bind(service, WellKnownFolderName:Calendar, new PropertySet()).

  cView = new CalendarView(apptStart, apptEnd, 5).

  cappt = calendar:FindAppointments(cView).

  message cappt:Subject.

Posted by tbergman on 26-Jun-2014 20:42

I’m not certain for appointments but for mail items the code in question would look something like.
 
DEF VAR myResults AS "FindItemsResults<Item>".
def var email as EmailMessage.
myResults = service:FindItems(WellKnownFolderName:Inbox,sFilter,myView).
email = cast(myResults:Items[0],EmailMessage).
 
Tom Bergman
Tom.Bergman@WoltersKluwer.com
 
[collapse]
From: thomas.rothlisberger [mailto:bounce-thomasrothlisberger@community.progress.com]
Sent: Thursday, June 26, 2014 8:06 PM
To: TU.OE.Development@community.progress.com
Subject: RE: [Technical Users - OE Development] Read appointments using exchange web service (EWS)
 
Reply by thomas.rothlisberger

Hi

I am using OE11.3 on windows Server 2008.

I have put together the following code but I can't figure out what sort of object I need in the find command (= calendar.findAppointments(cview). Using cappt is giving me incompatible data type. I tried various ones but can't get it to work.

Below is my code example:

USING System.*.

USING Microsoft.Exchange.WebServices.Data.*.

USING System.Net.Security.*.

USING System.Security.Cryptography.X509Certificates.*.

DEFINE VARIABLE service   AS ExchangeService.  

DEFINE VARIABLE ApptStart AS DATETIME.

DEFINE VARIABLE ApptEnd   AS DATETIME.

apptStart = NOW.

apptEnd = NOW + 3600000.

service = NEW ExchangeService(ExchangeVersion:Exchange2013) .

service:credentials = NEW WebCredentials("myemailaddress", "").

service:AutodiscoverUrl("myurl").

def var cView as Microsoft.Exchange.WebServices.Data.CalendarView.

def var calendar as Microsoft.Exchange.WebServices.Data.CalendarFolder.

def var cappt as Microsoft.Exchange.WebServices.Data.Appointment.

  calendar = CalendarFolder:Bind(service, WellKnownFolderName:Calendar, new PropertySet()).

  cView = new CalendarView(apptStart, apptEnd, 5).

  cappt = calendar:FindAppointments(cView).

  message cappt:Subject.

Stop receiving emails on this subject.

Flag this post as spam/abuse.

[/collapse]

Posted by thomas.rothlisberger on 27-Jun-2014 02:19

Hi Tom

You are a champion, that is exactly what I was looking for. Next time you are down under at the Progress Conference, I will buy you a beer or two.

cheers

Thomas

Posted by thomas.rothlisberger on 27-Jun-2014 02:35

Hi Tom

Appointments work the same as emails, I just had to replace the word 'emailMessage' with 'Appointment' and it worked.

Cheers

Thomas

This thread is closed