【发布时间】:2010-08-04 15:32:32
【问题描述】:
当我使用下面的 GMailReader 在 Android 开发环境中尝试 javamail/gmail store.connect 时,有时会收到“主机未解析:imap.gmail.com:993”。为什么有时会失败,而其他时候不会?
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;
}
}
【问题讨论】:
-
更新:我在N1上没有看到这个问题,所以可能是开发环境的缺陷,无法在目标机上重现。
标签: android gmail jakarta-mail