Take the 2-minute tour ×

An email is sent from lets say gg@gg.com with an attachment to 2 email id's .One, my email id and another xx@xx.com I got that email. When i did mail search using java Mail API with email id as search criteria , it is not able to find it though i received that email.But when i forward it to the same email id's search criteria is working fine. Please let me know when email is received for the first time at that point why it is not able to search

Properties properties = System.getProperties();
        properties.put("mail.smtp.host", ExchangeProperties.getSmtpHost());
        properties.put("mail.pop3.connectiontimeout", String.valueOf(ExchangeProperties.getPop3ConnectionTimeout() * 1000));
        properties.put("mail.pop3.timeout", String.valueOf(ExchangeProperties.getPop3Timeout() * 1000));
        session = Session.getInstance(properties, null);
        // Get the store
        store = session.getStore("pop3");
        store.connect(ExchangeProperties.getSmtpHost(), user, password);

 Folder folder = store.getFolder(folderName)
      Message[] foundMessages  = folder.search(andTerm); //andTerm contains email id
      FetchProfile fp = new FetchProfile();
                    folder.fetch(foundMessages, fp);
share|improve this question
add comment

1 Answer

Since you're using pop3, all the searching is done by downloading all the messages to the client and searching them there. If you want the server to do the searching, use imap.

If the new message arrives while you have the pop3 folder open, you won't be able to see it. You need to close the folder and reopen it. That's a limitation of the pop3 protocol.

If none of that helps with your problem, I would need to know exactly which search term you're using, exactly what value you're searching for, and exactly what value appears in the email header.

share|improve this answer
I am searching it using the search terms, Receipient term TO as email, header Term, subject term and ANDterm. I need to retrieve that email based on this and retrieve the attachment sent with that email and process that attachment further. is it possible with the 'imap' protocol? –  user2393330 Jul 25 '13 at 12:44
It should work, but the details matter. If you don't want to post the details here you can send them to me at javamail_ww@oracle.com. Also, for testing, try with only the Recipient term and with everything except the Recipient term and see if you get what you expect in each case. This should all work with imap as well, but imap has the advantage that the searching is done on the server. –  Bill Shannon Jul 25 '13 at 23:07
I have sent the details in mail. thanks –  user2393330 Jul 26 '13 at 9:55
Thanks.The issue is resolved –  user2393330 Jul 30 '13 at 7:28
add comment

Your Answer


