0

我开发了一个 webmail 来链接 apache james,它可以工作。但是有些用户无法收到来自 james 的电子邮件。我设置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) {
    }
}

我在这里发了一个帖子。感谢您的任何帮助!

4

2 回答 2

0

我不知道你为什么为此开始另一个线程......

你的服务器有问题。检查服务器日志。它使 STAT 命令失败,但没有报告失败的任何原因。

于 2012-11-15T19:20:46.923 回答
0

我与 Apache James 有过接触,终于找到了答案。你可以在这里找到它:STAT 命令偶尔失败。在页面的末尾,已列出该线程。

于 2012-11-30T02:02:47.867 回答