问题
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);
session.setDebug(logger.isDebugEnabled());
// 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();
fp.add(FetchProfile.Item.ENVELOPE);
folder.fetch(foundMessages, fp);
回答1:
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.
来源:https://stackoverflow.com/questions/17806024/not-able-to-search-the-email-server-with-searchterm-using-mail-api