注意:回答后添加:谢谢..是的,我曾尝试过Flag.SEEN为true和saveChanges ..我也读过了读取的getContent标记.我尝试在循环消息的for语句中使用它.但是我在下一个循环中再次从文件夹中收到了消息.我假设文件夹是实时的,所以抓住内容,然后从过滤器的文件夹中再次抓取消息,看不到任何看到应该工作,但我仍然得到相同的消息.我可以尝试关闭文件夹并重新打开作为测试,以查看它是否已标记.此外,如果我转到我的客户端并单击该消息,那么我的代码即使在循环中也不会再看到它,所以我希望在代码中也这样做.
original:我正在使用javamail从gmail帐户获取电子邮件,它工作得很好,当我收到消息时我想将其标记为已阅读,是否有人可以给我一些指示?这是我目前的代码:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("imap.gmail.com", eUserName, ePassWord);
// Get folder
Folder folder = store.getFolder("INBOX");
if (folder == null || !folder.exists()) {
return null;
}
folder.open(Folder.READ_ONLY);
// Only pull unread
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
Message messages[]; // = folder.search(ft);
for(int x = 0; x < timeOutInSeconds; x++) {
log.reportMessage("looking for emails");
try {
folder.getMessages();
messages = folder.search(ft);
if (messages.length > 0) { …Run Code Online (Sandbox Code Playgroud)