reading a new message from server which supports pop3 protocol
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   parag_desai
Posted On:   Sunday, June 17, 2001 11:27 PM

I am facing problem in reading the new messages from the server which supports pop3 protocol. I am giving a code .........can anybody tell me what is wrong with this code. I am able to compile this code .........but it seems that addMessageCountListener is not working or javamail doesn't support it. Also getNewMessageCount() method of folder is also not giving any output. Thanx in advance. CODE : import java.io.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*; import com.sun.mail.pop3.*; import javax.mail.event.*; import javax.activation.*; //public class contentsize1 implements MessageCountListener public    More>>

I am facing problem in reading the new messages from the server which supports pop3 protocol.
I am giving a code .........can anybody tell me what is wrong with this code.
I am able to compile this code .........but it seems that addMessageCountListener is not working or javamail doesn't support it.
Also getNewMessageCount() method of folder is also not giving any output.
Thanx in advance.


CODE :


import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import com.sun.mail.pop3.*;
import javax.mail.event.*;
import javax.activation.*;

//public class contentsize1 implements MessageCountListener
public class contentsize1 extends MessageCountAdapter
{
public static void main(String args[])
{
try
{
String host ="xyz.com";
String username = "xyz";
String password = "xyz";
int z ;

Session ses = Session.getInstance(System.getProperties(), null);

// Get the store
Store store = ses.getStore("pop3");
store.connect(host, username, password);

// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);

//Get content size
int count = folder.getMessageCount();
Message msg[]=folder.getMessages();
int newMessages = folder.getNewMessageCount();
System.out.println("Total MEssages:"+count);
System.out.println("New Messages:"+newMessages);



folder.addMessageCountListener(new MessageCountAdapter() {
public void messagesAdded(MessageCountEvent ev) {
Message[] msgs = ev.getMessages();
System.out.println("Got " + msgs.length + " new messages");

// Just dump out the new messages
for (int i = 0; i < msgs.length; i++) {
try {
DataHandler dh = msgs[i].getDataHandler();
InputStream is = dh.getInputStream();
int c;
while ((c = is.read()) != -1)
System.out.write(c);
} catch (IOException ioex) {
ioex.printStackTrace();
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
});


// Close connection
folder.close(false);

store.close();
}
catch (Exception e)
{
System.out.println("Erroe " + e.toString());
}
}
}

   <<Less

Re: reading a new message from server which supports pop3 protocol

Posted By:   kvu_kle  
Posted On:   Tuesday, July 24, 2001 01:25 PM

Unfortunately, pop3 doesn't support reading in "new" messages. Look at other protocols like IMAP.
About | Sitemap | Contact