我想在电子邮件应用程序中同步更改,然后在服务器电子邮件中自动更改。例如,我在电子邮件应用程序上阅读了未读邮件,然后自动服务器电子邮件将未读邮件更改为已读邮件。
我电子邮件应用程序使用了邮件jar文件、activation.jar和其他jar文件,以下代码用于将电子邮件应用程序连接到服务器电子邮件:
Properties props = System.getProperties();
props.setProperty("mail.store.protocol", "imaps");
props.put("mail.smtp.starttls.enable","true");
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("USEREMAILID","PASSWORD ");
}
};
sessioned= Session.getDefaultInstance(props, auth);
store = sessioned.getStore("imaps");
store.connect("smtp.gmail.com","USEREMAILID","PASSWORD ");
inbox = store.getFolder("inbox");
inbox.open(Folder.READ_ONLY);
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
UNReadmessages = inbox.search(ft);
发布于 2012-04-05 04:51:42
我已经解决了这个问题。
永远不要在运行时关闭连接,使用以下代码。
inbox.open(Folder.READ_WRITE);
发布于 2012-03-31 18:38:53
如果你是在“在线”状态下做这件事的,连接商店并打开文件夹,你通过JavaMail应用编程接口所做的更改会立即反映在服务器上。由您和您的程序逻辑来确保(例如)将消息标记为已读或未读的用户界面操作会导致相应的JavaMail操作。
还要注意,特别是对于" read“,获取消息内容将导致服务器将消息标记为已读,而不需要您执行任何其他显式操作。
如果你希望所有这些都在应用程序“离线”时发生,并在你下次在线时重新同步,那就更难了。JavaMail常见问题有一些建议可以帮助你做到这一点。
https://stackoverflow.com/questions/9953252
复制相似问题