打开javamail文件夹失败

时间:2012-11-13 07:57:00

标签: java email javamail james

我使用javamail和apache-james开发了一个电子邮件网站,它主要运行良好。但是有些用户获得了Open failed Exception并且无法接收新邮件。 接收电子邮件的代码:

Session mailSession = Session.getInstance(System.getProperties(), null);
mailSession.setDebug(false);
Store store = null;
Folder folder = null; //javax.mail.Folder
try {
    store = mailSession.getStore(SParam.PROTOCOL);
    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) {
        // TODO: handle exception
        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) {
    }
}

在大多数情况下,它运作得很好。但偶尔也会出现错误:

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

等待你的帮助,非常感谢!

我调试和调试,终于发现STAT命令失败了!当STAT命令出错时,詹姆斯有一个例外,但这没有任何意义!

21/11/12 14:39:16 ERROR pop3server: Exception during connection from 127.0.0.1     
    (127.0.0.1) : An exception occurred getting a database connection.
    org.apache.avalon.framework.CascadingRuntimeException: An exception occurred getting a database connection.
at org.apache.james.userrepository.AbstractJdbcUsersRepository.openConnection(AbstractJdbcUsersRepository.java:617)
    at org.apache.james.userrepository.AbstractJdbcUsersRepository.getUserByName(AbstractJdbcUsersRepository.java:521)
    at org.apache.james.userrepository.AbstractUsersRepository.test(AbstractUsersRepository.java:270)
    at org.apache.james.core.LocalUsersRepository.test(LocalUsersRepository.java:90)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.avalon.phoenix.components.application.BlockInvocationHandler.invoke(BlockInvocationHandler.java:134)
    at $Proxy4.test(Unknown Source)
    at org.apache.james.pop3server.POP3Handler.doPASS(POP3Handler.java:537)
    at org.apache.james.pop3server.POP3Handler.parseCommand(POP3Handler.java:479)
    at org.apache.james.pop3server.POP3Handler.handleConnection(POP3Handler.java:277)
    at org.apache.james.util.connection.ServerConnection$ClientConnectionRunner.run(ServerConnection.java:432)
    at org.apache.excalibur.thread.impl.ExecutableRunnable.execute(ExecutableRunnable.java:55)
    at org.apache.excalibur.thread.impl.WorkerThread.run(WorkerThread.java:116)
Caused by: java.sql.SQLException: Listener refused the connection with the following error:
    ORA-12519, TNS:no appropriate service handler found
    The Connection descriptor used by the client was: 192.168.250.23:1521:csmis
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
    at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:261)
    at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:387)
    at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:439)
    at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:165)
    at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:35)
    at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:801)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:37)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:290)
    at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:771)
    at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:95)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
    at org.apache.james.util.dbcp.JdbcDataSource.getConnection(JdbcDataSource.java:220)
    at org.apache.james.userrepository.AbstractJdbcUsersRepository.openConnection(AbstractJdbcUsersRepository.java:614)
... 15 more

所有应用程序都在同一台服务器上运行,并且只有少数用户在线(当我测试它时,只有我使用它)。错误偶尔会出现。为什么呢?

2 个答案:

答案 0 :(得分:0)

这似乎是邮件服务器问题。 STAT命令用于显示消息数。通常STAT是成功连接到邮件服务器后运行的第一个命令。

尝试使用mailSession.setDebug(true)进入调试模式以获取更多错误日志。

答案 1 :(得分:0)

我与Apache James有过接触,终于找到了答案。你可以在这里找到它:STAT command failed occasionally。在页面的末尾,列出了该主题。