我一直在尝试编写一个定期解析gmail消息内容的应用程序.我已经阅读了
JavaMail常见问题解答,我已经查看了JavaMail下载包中的一些示例,但无法使其工作.下面的代码当前导致以下gmail错误:
Host is unresolved: imaps.gmail.com:993
我也试过imap.gmail.com:143但得到:
Host is unresolved: imap.gmail.com:143
任何帮助或建议将不胜感激. GMailReader是我用来尝试返回gmail imap消息的类:
public class GMailReader extends javax.mail.Authenticator { private String mailhost = "imaps.gmail.com"; private String user; private String password; private Session session; public GMailReader(String user,String password) { this.user = user; this.password = password; Properties props = new Properties(); props.setProperty("mail.transport.protocol","imaps"); props.setProperty("mail.imaps.host",mailhost); props.put("mail.imaps.auth","true"); props.put("mail.imaps.port","993"); props.put("mail.imaps.socketFactory.port","993"); props.put("mail.imaps.socketFactory.class","javax.net.ssl.SSLSocketFactory"); props.put("mail.imaps.socketFactory.fallback","false"); props.setProperty("mail.imaps.quitwait","false"); session = Session.getDefaultInstance(props,this); } public synchronized Message[] readMail() throws Exception { try { Store store = session.getStore("imaps"); store.connect("imaps.gmail.com",user,password); Folder folder = store.getFolder("INBox"); folder.open(Folder.READ_ONLY); Message[] msgs = folder.getMessages(1,10); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); folder.fetch(msgs,fp); return msgs; } catch (Exception e) { Log.e("readMail",e.getMessage(),e); return null; } } }