我想使用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
答案 0 :(得分:0)
鉴于它似乎抱怨对CAPA的意外响应,可能是您的邮件服务器发送了非标准响应。您可以尝试将mail.pop3.disablecapa
设置为true,这样就不会发送CAPA。
作为旁边System.getProperties();
返回一个共享的Properties对象,不确定这是否是你想要的。也许改为new Properties();
?