我开发了一个链接apache james的webmail,但它确实有用。但有些用户无法接收来自詹姆斯的电子邮件。我设置mailSession.setDebug(true)
并跟踪两个用户的日志(sa可以接收,另一个不能)。差异如下:
可以成功接收电子邮件的用户(用户sa):
[2012-11-15 14:24:12] com.csc.mail.jsh.mail.core.ReceiveMail : [INFO ] - trying to receive emails from james server...
C: STAT
S: +OK 2 2584
C: NOOP
S: +OK
C: TOP 1 0
S: +OK Message follows
...
其他用户收到失败(用户chai):
[2012-11-15 14:22:01] com.csc.mail.jsh.mail.core.ReceiveMail : [INFO ] - trying to receive emails from james server...
C: STAT
S: -ERR
C: QUIT
S: +OK Apache James POP3 Server signing off.
[2012-11-15 14:22:03] com.csc.mail.jsh.mail.core.ReceiveMail : [ERROR] - Folder open failed:javax.mail.MessagingException: Open failed;
nested exception is:
java.io.IOException: STAT command failed: null
at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:228)
at com.csc.mail.jsh.mail.core.ReceiveMail.receive(ReceiveMail.java:82)
at com.csc.mail.jsh.mail.core.ReceiveMail.run(ReceiveMail.java:222)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.io.IOException: STAT command failed: null
at com.sun.mail.pop3.Protocol.stat(Protocol.java:366)
at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:203)
... 3 more
我的接收代码:
Session mailSession = Session.getInstance(System.getProperties(), null);
mailSession.setDebug(true);
Store store = null;
Folder folder = null; //javax.mail.Folder
try {
store = mailSession.getStore("pop3");
store.connect(Property.getPop3(), userName, password);
logger.info("trying to receive emails from james server...");
folder = store.getFolder("INBOX");
try {
if (!folder.isOpen()) {
folder.open(Folder.READ_WRITE); //the point of throwing the exception
}
} catch (Exception e) {
e.printStackTrace();
}
//receive email from james server.
} catch (Exception e) {
logger.error("Email Receive Error!" + StackTraceStr.st2str(e));
try {
folder.close(true);
} catch (Exception e2) {
}
} finally {
try {
store.close();
} catch (Exception cloex) {
}
}
我在here张贴了一篇帖子。谢谢你的帮助!
答案 0 :(得分:0)
我不确定你为什么要为此开始另一个线程...
您的服务器出了问题。检查服务器日志。它没有通过STAT命令,但没有报告任何失败的原因。
答案 1 :(得分:0)
我与Apache James有过接触,终于找到了答案。你可以在这里找到它:STAT command failed occasionally。在页面的末尾,列出了该主题。