dcsimg
How can I get messages from a pop Inbox folder
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jalana_Jayasinghe
Posted On:   Tuesday, June 12, 2001 11:37 AM

Following is the code for getting messages from a pop Inbox folder. It runs fine until it comes to the code for getting the no. of messages in the folder and printing the messages. The code always returns the no. of messages in the inbox folder as 0 which I know is not right. Can you please help me. Thanks Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("pop3"); store.connect( mailHost, "jjay2", "nilanka2" ); System.out.println( "1" ); Folder folder = store.getFolder( "Inbox" ); System.out.println( "1.5" ); fo   More>>

Following is the code for getting messages from a pop Inbox folder.
It runs fine until it comes to the code for getting the no. of messages in
the folder and printing the messages. The code always returns the no.
of messages in the inbox folder as 0 which I know is not right. Can you
please help me. Thanks




Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("pop3");
store.connect( mailHost, "jjay2", "nilanka2" );
System.out.println( "1" );

Folder folder = store.getFolder( "Inbox" );
System.out.println( "1.5" );
folder.exists();
System.out.println( "2" );

folder.open( folder.READ_ONLY );
System.out.println( "3" );
BufferedReader reader = new BufferedReader (
new InputStreamReader(System.in));
System.out.println( "4" );

int totalMessages = folder.getMessageCount();
int newMessages = folder.getNewMessageCount();
System.out.println( totalMessages );
System.out.println( "4.25" );
System.out.println( newMessages );
System.out.println( "4.5" );

Message message[] = folder.getMessages();
System.out.println( "5" );
int x = message.length;
System.out.println( x );

*********** Code after this point is not executed*************

for (int i=0, n=message.length; i
System.out.println(i + ": " + message[i].getFrom()[0]
+ " " + message[i].getSubject());

System.out.println( "6" );
// Display from field and subject

System.out.println("Do you want to read message? [YES to read/QUIT to end]");
System.out.println( "7" );
String line = reader.readLine();
System.out.println( "8" );
if ("YES".equals(line)) {

// Display message content
System.out.println(message[i].getContent());
}

//System.out.println( "9" );
else if ("QUIT".equals(line)) {
break;
//System.out.println( "10" );
}

// Close connection
folder.close(false);
System.out.println( "9" );
store.close();
System.out.println( "10" );
}



}
}

   <<Less
About | Sitemap | Contact