quand je cours le code je reçois seulement de vieux mails, mais j'ai besoin d'obtenir un courrier avec un sujet spécial, qui est un nouveau courrier non lu ..... quel est le problème?JavaMail IMAP. Je ne reçois pas les nouveaux mails
grâce
public static void dumpMail() throws FileNotFoundException, IOException, MessagingException, FolderClosedException, SocketTimeoutException {
Properties props = new Properties();
String username = "ad\\" + "x";
String password = "y";
props.put("mail.imaps.host", "z");
props.put("mail.imaps.port", "993");
props.put("mail.imaps.connectiontimeout", "10000");
props.put("mail.imaps.timeout", "10000");
props.put("host", "z");
props.put("user", username);
props.put("pass", password);
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("z", username, password);
Folder inbox = store.getFolder("inbox");
inbox.open(Folder.READ_ONLY);
Flags seen = new Flags(Flags.Flag.SEEN);
FlagTerm unseenFlagTerm = new FlagTerm(seen, false);
Flags recent = new Flags(Flags.Flag.RECENT);
FlagTerm recentFlagTerm = new FlagTerm(recent, true);
SearchTerm searchTerm = new AndTerm(unseenFlagTerm, recentFlagTerm);
Message[] messages = inbox.search(searchTerm);
for (int i = 0; i < 30; i++) {
if (messages[i].getSubject().contains("Zeiterfassung")) {
System.out.println(messages[i].getContent());
}
}
}