subscribeToPullNotifications doesn't detect new emails in inbox
Asked Answered
S

1

7

i am trying to detect new emails in inbox using subscribeToPullNotifications as follows:

PullSubscription subscription = service.subscribeToPullNotifications(
                folder, 1, null, EventType.NewMail);

        GetEventsResults events = subscription.getEvents();
        System.out.println("####### EVENTS: "
                + events.getItemEvents().toString());
        for (ItemEvent itemEvent : events.getItemEvents()) {
            if (itemEvent.getEventType() == EventType.NewMail) {
                EmailMessage message = EmailMessage.bind(service,
                        itemEvent.getItemId());
                System.out.println("######## NEW EMAIL MESSAGE IS: "
                        + message.getSubject());
            }
        }

but the events.getItemEvents() is always empty, even i can see new emails in the inbox. also how to make the above code is always repeated while the application is running, so that each minute it check for new emails.

Santana answered 18/11, 2012 at 13:30 Comment(0)
S
2

Here it depends on when you are calling this, if suppose you are calling this as particular interval then you need to pass "WaterMark" of previous response in new request, else all events which occurred in between would be lost. method : subscription.getWaterMark()

need to pass this as thrid argument to method subscribeToPullNotifications()

else you can continously pull on the same service by placing that in loop :

 while (true) {

    GetEventsResults events = null;

    try {
         events = subscription.getEvents();
    } catch (Exception e1) {
         e1.printStackTrace();
    }

    for (ItemEvent itemEvent : events.getItemEvents()) {
        // do something...
    }

 }

But this would continuously pull from server increasing load, so rather use first approach by subscribing at regular interval, and passing previous water-mark in request.

Stanwood answered 17/12, 2013 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.