I'm using javamail libs to develop simple apps to sending encrypted mail via gmail. after travelling and googling everywhere, it is finnaly done. At least until i run it again this night, suddenly it doesnt read any email other from google.
My code is like this
public static void check(String host, String storeType, String user,
String password) {
try {
//create properties field
Properties properties = new Properties();
properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "995");
properties.put("mail.pop3.starttls.enable", "true");
Session emailSession = Session.getDefaultInstance(properties);
//create the POP3 store object and connect with the pop server
Store store = emailSession.getStore("pop3s");
store.connect(host, user, password);
//create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
// retrieve the messages from the folder in an array and print it
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0, n = messages.length; i < n; i++) {
Message message = messages[i];
System.out.println("---------------------------------");
System.out.println("Email Number " + (i + 1));
System.out.println("Subject: " + AESencrp.decrypt(message.getSubject()));
System.out.println("From: " + message.getFrom()[0]);
System.out.println("Text: " + AESencrp.decrypt(message.getContent().toString()));
}
//close the store and folder objects
emailFolder.close(false);
store.close();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
It simply show email from google, however there is another 3 email from other address. I didn't understand, last time I run that code, it works flawlessly. Note that im not making any change to the code from last time run success.
These JavaMail FAQ entries might help: