Results 1 to 7 of 7
  1. #1
    aby
    aby is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Mail reading issue using pop3 in java mailing

    HI ALL,

    My Mail reading functionality is not working properly using POP3 protocol.
    Actually I can read the mail but the status is not changed as read. Please help me.

    Java Code:
    public static void main(String arg[]) throws MessagingException, IOException{
    		
    
    	   String host = "pop.test.net";
            String user = "test@beq.com";	      
            String password = "abc10";
            String protocol = "pop3";
           
    	    Properties props = new Properties();
    	    props.put("mail.store.protocol", protocol);
            props.put("mail.pop3.host", host);     
            props.put("mail.pop3.user",user);      
            props.put("mail.transport.protocol",protocol); 
             
            Session session = Session.getDefaultInstance(props, null);
       	    Store store=null;
    		try {
    			store = session.getStore(protocol);		
    			store.connect(host, user, password);
    			
    		} catch (Exception e) {
    		}
    	    Folder inbox = store.getFolder("Inbox");
    	    inbox.open(Folder.READ_WRITE);
    	    Message[] messages = inbox.getMessages();
    	    
    	    for (int i = 0; i < messages.length; i++) {     
    	      messages[i].writeTo(System.out);
    	    }
    	    inbox.close(false);
    	    store.close();
    	  }
    Thanks,
    Aby

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Mail reading issue using pop3 in java mailing

    You've never changed the status of the messages. The status doesn't change automagically.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    aby
    aby is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Mail reading issue using pop3 in java mailing

    Thank you for the reply.

    I have tried the flag setting also but it is not reflecting

    messages[i].setFlag((Flags.Flag.SEEN), true);

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Mail reading issue using pop3 in java mailing

    You also have to call messages[i].saveChanges() to actually change the Seen flag.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    aby
    aby is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Mail reading issue using pop3 in java mailing

    I have called messages[i].saveChanges() but I am getting an exception as

    javax.mail.IllegalWriteException: POP3 messages are read-only at com.sun.mail.pop3.POP3Message.saveChanges(POP3Mess age.java:450)

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: Mail reading issue using pop3 in java mailing

    Oh, yes. POP3 Messages cannot be changed, as the API doc states: saveChanges()
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,876
    Rep Power
    5

    Default Re: Mail reading issue using pop3 in java mailing

    Probably you'd need to use IMAP to be able to do that, but that's a guess on my part.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Java Mail Issue
    By rdcian in forum Advanced Java
    Replies: 0
    Last Post: 10-19-2012, 08:20 AM
  2. Issue reading 375M text file with java
    By Nish_biz in forum Advanced Java
    Replies: 11
    Last Post: 12-12-2011, 12:33 PM
  3. Replies: 1
    Last Post: 05-18-2011, 02:08 AM
  4. mailing concept in java
    By sniffer139 in forum Networking
    Replies: 1
    Last Post: 02-22-2010, 10:34 AM
  5. error in reading mail contents
    By kib_tse in forum Networking
    Replies: 1
    Last Post: 08-22-2008, 12:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •