问题
I developed a webmail to link apache james and it works. But some user cannot receive emails from james. I set mailSession.setDebug(true)
and trace two users' logs(sa can receive, the other cannot). The difference shows below:
the user who can receive email successfully(user 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
...
the other user receive failure(user 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
My receive code:
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) {
}
}
I had posted a post at here. Thanks for your any help!
回答1:
I'm not sure why you started another thread for this...
There's something wrong with your server. Check the server logs. It's failing the STAT command but not reporting any reason for the failure.
回答2:
I had contact with Apache James and finally found the answer. You can find it at here: STAT command failed occasionally. At the end of the page, the thread had been listed.
来源:https://stackoverflow.com/questions/13393347/cant-receive-emails-from-apache-james