开发者

How to read all email?

开发者 https://www.devze.com 2023-03-19 20:16 出处:网络
I am trying to fetch all email using the following code, but this code read all UNREAD messages however I want to read all Read/unread email.

I am trying to fetch all email using the following code, but this code read all UNREAD messages however I want to read all Read/unread email.

 try {
        Properties props = (Properties)System.getProperties().clone();
        session = Session.getInstance(props);    
        store = session.getStore("pop3s");
        store.connect(host,username,password);
        folder = store.getFolder("INBOX");      
        folder.open(Folder.READ_WRITE);
        Message[] message = folder.getMessages();     

        for (int i=0, n=message.length; i<n; i++)
        {
           System.out.println(i + ": " + message[i].getFrom()[开发者_StackOverflow0] 
             + "\t" + message[i].getSubject());
        }
}catch (MessagingException e) {e.printStackTrace();}

can anyone please help me to read all email.

Thanks Monali


The standard behavior with the POP3 protocol is that clients usually delete all messages that they've received from the server. Autodelete is not part of the protocol, it's more or less a convention or best practise that POP3 clients send delete commands after they received all emails.

According to this, a server does not have any read messages. All messages you can read are unread. And even if you leave messages on the server, you can't flag them as read/unread there.

That's different with IMAP protocol, where emails stay on the the server as long as you delete them, usually from your email client.

0

精彩评论

暂无评论...
验证码 换一张
取 消