admin管理员组文章数量:1405124
I am trying to create an Application that reads my Emails, and I read about the IdleManager. My understanding is, that you just add the Folder you want to watch over, create an MessageCountListener and thats it.
Apart from adding the Properties "mail.event.scope" and "mail.event.executor"
Am I doing something wrong or is it just not working?
private Session session;
private Store store;
private IMAPFolder inboxFolder;
private ExecutorService es;
private JakartaGmailReader() {
this.es = Executors.newCachedThreadPool();
try {
this.password = Files.readString(Path.of(this.getClass()
.getResource("/AppPasswortGmail.txt")
.toURI()));
this.createSession();
this.createStore();
this.inboxFolder = this.getFolderFromStore("INBOX");
this.inboxFolder.addMessageChangedListener(e -> {
System.out.println("MessageChange Listener");
System.out.println(e);
});
this.inboxFolder.addMessageCountListener(new MessageCountListener() {
@Override
public void messagesRemoved(MessageCountEvent e) {
System.out.println("Removed");
System.out.println(e);
}
@Override
public void messagesAdded(MessageCountEvent e) {
System.out.println("Added");
System.out.println(e);
}
});
IdleManager idleManager = new IdleManager(this.session, this.es);
idleManager.watch(this.inboxFolder);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
private void createSession() {
this.session = Session.getInstance(this.getImapProperties());
}
private void createStore() throws MessagingException {
this.store = this.session.getStore("imaps");
this.store.connect("imap.gmail", JakartaGmailReader.EMAIL, this.password);
}
private Properties getImapProperties() {
Properties props = new Properties();
props.put("mail.imaps.host", "imap.gmail");
props.put("mail.imaps.ssl.trust", "imap.gmail");
props.put("mail.imaps.port", "993");
props.put("mail.imaps.starttls.enable", "true");
props.put("mail.imaps.connectiontimeout", "10000");
props.put("mail.imaps.timeout", "10000");
props.put("mail.imaps.usesocketchannels", "true");
props.put("mail.event.scope", "session"); // or "application"
props.put("mail.event.executor", this.es);
props.put("mail.store.protocol", "imaps");
return props;
}
private IMAPFolder getFolderFromStore(String folderName) throws MessagingException {
IMAPFolder folder = (IMAPFolder) this.store.getFolder(folderName);
folder.open(Folder.READ_WRITE);
return folder;
}
本文标签: javaIs Jakarta Mail Idle Manager not workingStack Overflow
版权声明:本文标题:java - Is Jakarta Mail Idle Manager not working? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744279440a2598577.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论