Problem in Reading Mail
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   shailesh_jammie
Posted On:   Monday, November 14, 2005 04:18 AM

hi i m using java mail api for reading mail, here is my code provided authentication is ok try { // -- Get hold of the default session -- Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props, null); // -- Get hold of a POP3 message store, and connect to it -- store = session.getStore("pop3"); store.connect("my-domain", "my-mailid", "my-password"); System.out.println(store.isConnected()); // -- Try to get hold of the default folder -- folder = store.getDefaultFolder(); if (folder == null) throw new Exception("No default folder"); // --    More>>

hi
i m using java mail api for reading mail,
here is my code provided authentication is ok
try
{
// -- Get hold of the default session --
Properties props = System.getProperties();
Session session = Session.getDefaultInstance(props, null);

// -- Get hold of a POP3 message store, and connect to it --
store = session.getStore("pop3");
store.connect("my-domain", "my-mailid",
"my-password");
System.out.println(store.isConnected());

// -- Try to get hold of the default folder --
folder = store.getDefaultFolder();
if (folder == null) throw new Exception("No default folder");

// -- ...and its INBOX --
folder = folder.getFolder("INBOX");
if (folder == null) throw new Exception("No POP3 INBOX");
System.out.println(folder.getMessageCount());

// -- Open the folder for read only --
folder.open(Folder.READ_ONLY);

System.out.println(folder.getMessageCount());
// -- Get the message wrappers and process them --
Message[] msgs = folder.getMessages();
System.out.println("msg array length..."+msgs.length);
for (int msgNum = 0; msgNum < msgs.length; msgNum++)
{

printMessage(msgs[0]);
}

}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
// -- Close down nicely --
try
{
if (folder!=null) folder.close(false);
if (store!=null) store.close();
}
catch (Exception ex2)
{
ex2.printStackTrace();
}
but i m getting 0 length array of messages from folder.getMessages();
can anyone tell me the solution !!
i wll b oblized
regards
shailesh

   <<Less

Re: Problem in Reading Mail

Posted By:   Christopher_Koenigsberg  
Posted On:   Sunday, November 20, 2005 06:50 PM

How many unread messages are actually there?
About | Sitemap | Contact