//preparing session information for connecting to the serverProperties props =NewProperties (); Props.setproperty ("Mail.store.protocol","IMAP"); Props.setproperty ("Mail.imap.host","imap.163.com"); Props.setproperty ("Mail.imap.port","143"); //Create session Instance objectSession session =session.getinstance (props); //Create a Store object for the IMAP protocolStore store = Session.getstore ("IMAP"); //connecting to a mail serverStore.connect ("186*******","111111"); //Get InboxFolder folder = Store.getfolder ("INBOX"); //open Inbox in read-write modeFolder.open (Folder.read_write); //get a mailing list for your Inboxmessage[] Messages =folder.getmessages (); //Print the number of messages in different StatesSystem. out. println ("Inbox"+ Messages.length +"e-mail!"); System. out. println ("Inbox"+ folder.getunreadmessagecount () +"e-mail unread!"); System. out. println ("Inbox"+ folder.getnewmessagecount () +"New Email!"); System. out. println ("Inbox"+ folder.getdeletedmessagecount () +"deleted Messages!"); System. out. println ("------------------------Start parsing messages----------------------------------"); //parsing Messages for(Message message:messages) {imapmessage msg=(imapmessage) message; Msg.setflag (Flags.Flag.SEEN,true);//String subject = Mimeutility.decodetext (Msg.getsubject ());//System.out.println ("[" + Subject + "] unread, do you need to read this message (yes/no)? ");//BufferedReader reader = new BufferedReader (new InputStreamReader (system.in));//String answer = Reader.readline (); //www.2cto.com//if ("Yes". Equalsignorecase (Answer)) {////Pop3receivemailtest.parsemessage (msg); Parsing Messages// //The second parameter, if set to true, will modify the feedback to the server. False does not give feedback to the server//Msg.setflag (Flags.Flag.SEEN, true); //Set Read Flag// } } //Close ResourceFolder.close (false); Store.close ();
POP3 is not allowed to change the status of the message,
So use IMAP protocol instead
Java Mail reads the mailing list,