我想使用 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