1
我正在理解javax.mail來閱讀一個電子郵件帳戶並獲取所有收到的消息。 這是一個例子:如何知道消息是否被讀取
Properties properties = System.getProperties();
properties.setProperty("mail.store.protocol", "imaps");
try {
Session session = Session.getDefaultInstance(properties, null);
//create session instance
Store store = session.getStore("imaps");//create store instance
store.connect("pop.gmail.com", "[email protected]", "***");
//set your user_name and password
System.out.println(store);
Folder inbox = store.getFolder("inbox");
//set folder from where u wants to read mails
inbox.open(Folder.READ_ONLY);//set access type of Inbox
Message messages[] = inbox.getMessages();// gets inbox messages
for(Message message:messages) {
System.out.println(message.getContent().toString());
}
store.close();
} catch (Exception e) {
System.out.println(e);
}
我的問題是:
從Message messages[]
可以知道,如果消息是新的或不?例如:
for(Message message: messages){
if(message.isNew()) OR if(!message.isRead()){
System.out.println("Message is not still read");
}
}
有人能幫助我嗎?謝謝!!!
看到其他的問題(你稍有不同,OP代碼演示瞭如何的完成http://stackoverflow.com/ questions/5366767/retrieve-unread-emails-from-gmail-javamail-api-imap) – BigMike