properties.put("mail.imap.host", host);
properties.put("mail.imap.port", "993");
Session emailSession = Session.getDefaultInstance(properties);
Store store = emailSession.getStore("imaps");
store.connect(host, username, password);
This code is working well, but if the mail server is down, I got the expection:
javax.mail.MessagingException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?;
nested exception is:
com.sun.mail.iap.ConnectionException: * BYE JavaMail Exception: java.io.IOException: Connection dropped by server?
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:731)
at javax.mail.Service.connect(Service.java:366)
at javax.mail.Service.connect(Service.java:246)
at eugene.neocortex.fm.mail.check.CheckingMails.fetch(CheckingMails.java:100)
So I need to check if server is available? And I read the documentation of javax.mail and cant find method, how do I can check if server is alive? Method isConnected() checks if currently connected, but I need to check connection to my mail server before this code or I got exception again on this code string:
Store store = emailSession.getStore("imaps");