I sometimes get "Host is unresolved: imap.gmail.com:993" when I try the javamail/gmail store.connect in the Android development environment using GMailReader below. Why might this fail sometimes and not others?
public class GMailReader extends javax.mail.Authenticator {
private String user;
private String password;
public GMailReader(String user, String password) {
this.user = user;
this.password = password;
}
public int getUnreadMessageCount() throws Exception {
try {
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
Session session = Session.getInstance(props, this);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", user, password);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
int unreadMessageCount = inbox.getUnreadMessageCount();
return unreadMessageCount;
} catch (Exception e) {
Log.e("getUnreadMessageCount", e.getMessage(), e);
return -1;
}
}