0

我想使用 java mail api 从用户帐户中读取邮件。

邮件服务器是一个特定的邮件服务器:

ReadEMail.java - 客户端

Properties props = System.getProperties();
props.put("mail.debug", "true");
props.put("mail.pop3.host", host);
props.put("mail.pop3.port", port);
props.put("mail.pop3.user", username);
props.put("mail.pop3.timeout", "158000");
props.put("mail.pop3.connectiontimeout", "158000");
/*  Create the session and get the store for read the mail. */
session = Session.getInstance(props);
store = session.getStore("pop3");
session.setDebug(true);
store.connect(host,username, password);

客户端的错误信息:

DEBUG POP3: mail.pop3.apop.enable: false

DEBUG POP3: mail.pop3.disablecapa: false
DEBUG POP3: connecting to host "localhost", port 4444, isSSL false
S: +OK  Mail Server Ready 
C: CAPA
S: 
javax.mail.MessagingException: Connect failed;
  nested exception is:
    java.io.IOException: Unexpected response: 
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:210)
    at javax.mail.Service.connect(Service.java:295)
    at javax.mail.Service.connect(Service.java:176)
    at com.mail.reader.MailReader.connect(MailReader.java:67)
    at com.mail.reader.TestMailReader.main(TestMailReader.java:21)
Caused by: java.io.IOException: Unexpected response: 
    at com.sun.mail.pop3.Protocol.readResponse(Protocol.java:752)
    at com.sun.mail.pop3.Protocol.multilineCommand(Protocol.java:766)
    at com.sun.mail.pop3.Protocol.capa(Protocol.java:675)
    at com.sun.mail.pop3.Protocol.<init>(Protocol.java:140)
    at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261)
    at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206)
    ... 4 more
4

1 回答 1

0

鉴于它似乎抱怨对 CAPA 的意外响应,可能是您的邮件服务器发送了非标准响应。您可以尝试设置mail.pop3.disablecapa为 true,这样它就不会发送 CAPA。

顺便System.getProperties();说一句,返回一个共享的 Properties 对象,不确定这是否是您的意图。也许做一个new Properties();

于 2013-04-10T13:32:11.327 回答