一个javamail的老问题,已查阅论坛内其他帖子,暂无好方法

Great6661 2012-05-19 12:37:11
使用javamail以pop3、只读的方式收取邮件,而不留下任何痕迹。

目前遇到的问题如下:

程序在收取公司exchange邮箱里的邮件后,会将服务上的邮件标记为已读,这恰恰是不我希望的。


而在测试163邮箱的时候,同样的代码,却不会改变服务器上的邮件标记。


不知道是哪里出了问题,在线急等答案,问题解决后,速结贴!

最后附上部分源代码:

Session session = Session.getInstance(prop, null);
session.setDebug(false); // 是否启用debug模式
Folder folder = null;
Store store = null;
try {
store = session.getStore("pop3"); // 使用pop3会话机制,连接服务器
store.connect(pop3Server, port, loginName, password);
}
folder = store.getFolder("INBOX"); // 收件箱

folder.open(Folder.READ_ONLY);
// 得到收件箱文件夹信息,获取邮件列表
Message[] msgs = folder.getMessages();
int iemmalcount=0;

for (int i = 0; i < msgs.length; i++) {
if (isResumeEmail(resumeFromEmail, msgs[i]) && isNewEmail(lastSyncDateTime, msgs[i])) {
iemmalcount=iemmalcount+1;
resumesName = downLoadResumeByType(resumeType, msgs[i], resumesName, zipForderPath, htmlForderPath);
// 设置最后邮件时间
setLastMailDateTime(msgs[i]);

}
}

System.out.println("从上次:"+lastSyncDateTime+"到现在,共收到来自"+resumeFromEmail+"邮件"+iemmalcount+"封");

return resumesName;
} catch (Exception e) {
logger.error("网络故障或邮件配置错误,系统不能连接邮箱服务器!");
//logger.error("Network failure or mail configuration errors, the system can not connect to mail server.");
e.printStackTrace();
return null;
} finally {
// 释放资源
try {

if (folder != null) folder.close(false); //
if (store != null) store.close();
} catch (Exception bs) {
bs.printStackTrace();
}
}


...全文
175 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

535

社区成员

发帖
与我相关
我的任务
社区描述
企业开发 Exchange Server
社区管理员
  • 消息协作社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧