Reputation: 1934
I am trying to access mailinators messages using JavaMail API.
I can properly connect to the server etc. but when it comes to reading a message I keep receiving "Folder is not Open" exception, and when I am checking if folder is open and if not opening the folder, that wont help either. I guess for some reason mailinator ends the connection or so.
If I try to get inputstream of message instead of using getContent I can read from the inputstream fine and it contains the styling of the message etc. but for some reason it seems like the data i read from inputstream doesnt contain the message body..
If this is about mailinator or you could offer me any other random email reading service that supports pop3 or other easily readable, it doesn't really matter if I use mailinator for this project.
My current mail reading code.
private void checkMail(String user) {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
try {
Store store = session.getStore("pop3");
store.connect("pop.mailinator.com", 110, user, "12345678");
Folder inbox = store.getFolder("inbox");
if(inbox == null) {
System.out.println("no inbox");
} else {
inbox.open(Folder.READ_ONLY);
for(Message message: inbox.getMessages()) {
byte[] buffer = new byte[10000];
int read = 0;
try {
while((read = message.getInputStream().read(buffer, 0, 1024)) > 0) {
for(int i = 0; i < buffer.length; i++) {
System.out.print((char)buffer[i]);
}
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
/*try {
System.out.println(message.getContent().toString());
} catch (IOException e) {
e.printStackTrace();
}*/
}
}
inbox.close(false);
store.close();
} catch (NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MessagingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
also when reading from inputstream it looks like the inputstream is never ending, just starting over. My purpose is to get the message body and subject.
Upvotes: 3
Views: 3830
Reputation: 38177
Some time in the past, Mailinator changed the behavior, forbidding POP3 access, (or only reserving for paying customers). Maybe that was your problem (if the code worked with another mail provider).
Upvotes: 1
Reputation: 29971
If you're reading the InputStream from the message then clearly the folder is open. When are you getting the "Folder is not open" exception? What does the protocol trace show? You can try using Gmail if you think your server is port of the problem. Also, you'll want to fix your use of getDefaultInstance.
Upvotes: 0