Search code examples
javaoutlookexchange-serverewsjavaapi

How to react on newly created Appointments?


I am looking for a way to get a delta of Appointments. Basically what I want is to react on newly created Appointments.

To get newly created / unread messages there is a SearchFilter in the java ews api that I use. Unfortunately AppointmentSchema does not provide any fitting Enum for the filter.

new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));

I get the Appointments like:

    CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());
    var result = calendarFolder.findAppointments(cView);

so back to my question. How can I notice if someone invited me to a new Appointment or an email with a new Appointment invitation?


Solution

  • I have already found a solution, luckily. MeetingRequest is the Item I am looking for.

    FindItemsResults<Item> result = service.findItems(new FolderId(WellKnownFolderName.Inbox, new Mailbox(getCredentials())), getUnreadEmailFilter(), new ItemView(10));
    result.forEach(n -> {
        if (n instanceof MeetingRequest) {
           System.out.println("New Appointment - MeetingRequest found!");
           MeetingRequest req = (MeetingRequest) n;
           req.accept(true);
        }
    }