Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
JWebDAV for Exchange
>
Tutorial
> Monitor for new mail
The following example shows you how to monitor for new mail.
import com.independentsoft.webdav.exchange.Mailbox; import com.independentsoft.webdav.exchange.NotificationType; import com.independentsoft.webdav.exchange.Subscription; import com.independentsoft.webdav.exchange.WebdavClient; import com.independentsoft.webdav.exchange.WebdavException; public class Example { public static void main(final String[] args) { try { WebdavClient client = new WebdavClient("https://myserver/exchange/emailaddress", "username", "password"); Mailbox myMailbox = client.getMailbox("https://myserver/exchange/emailaddress"); //set subscription Subscription subscription = client.subscribe(myMailbox.getInbox(), NotificationType.NEW_MAIL, 3600); while (true) { Thread.currentThread().join(60000); Subscription pollSubscription = client.poll(myMailbox.getInbox(), subscription.getID()); if (pollSubscription.getStatus().equals("HTTP/1.1 200 OK")) { System.out.println("You have new mail!"); } } } catch (WebdavException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } } }