public Message[] getMail(String host, String name, String password) throws Exception {
Properties prop = new Properties();
prop.put("mail.pop3.host", host);
Session session = Session.getDefaultInstance(prop);
store = session.getStore("pop3");
store.connect(host, name, password); inbox = store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY); Message[] msg = inbox.getMessages(); FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
inbox.fetch(msg, profile); return msg;
}??每次运行这段代码, 总会得到一些相同的邮件, 我只希望得到最新的邮件(即上次运行此代码到目前为止这段时间所收到的邮件), 要怎么办,谢谢谢谢.
Properties prop = new Properties();
prop.put("mail.pop3.host", host);
Session session = Session.getDefaultInstance(prop);
store = session.getStore("pop3");
store.connect(host, name, password); inbox = store.getDefaultFolder().getFolder("INBOX");
inbox.open(Folder.READ_ONLY); Message[] msg = inbox.getMessages(); FetchProfile profile = new FetchProfile();
profile.add(FetchProfile.Item.ENVELOPE);
inbox.fetch(msg, profile); return msg;
}??每次运行这段代码, 总会得到一些相同的邮件, 我只希望得到最新的邮件(即上次运行此代码到目前为止这段时间所收到的邮件), 要怎么办,谢谢谢谢.
1. it should be inbox.open(Folder.READ_WRIGHT rather than Folder.READ_ONLY
2. Set each message deleted flag: msg[i].setFlag(Flags.Flag.DELETED, true);
3. When close the folder inbox, use inbox.close(true).