Java Mail reads the mailing list,

Source: Internet
Author: User
Tags imap

        //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,

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.