Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Mailinator POP3 using JavaMail

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.

like image 488
Ruuhkis Avatar asked Jan 23 '26 13:01

Ruuhkis


1 Answers

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).

like image 138
serv-inc Avatar answered Jan 25 '26 03:01

serv-inc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!