此代码旨在从 rediff 帐户获取主题和发件人地址。但事实并非如此。
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.swing.*;
class NewClass {
public static void main(String args[]) {
Properties props = new Properties();
props.put("mail.pop3.host" , "pop.rediffmail.com" );
props.put("mail.pop3.user" , "username");
// User SSL
props.put("mail.pop3.socketFactory" , 110);
props.put("mail.pop3.socketFactory.class" , "javax.net.ssl.SSLSocketFactory" );
props.put("mail.pop3.port" , 110 );
Session session = Session.getDefaultInstance(props , new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("username" , "password");
}
});
try {
Store store = session.getStore("pop3");
store.connect("pop.rediffmail.com" , "username" , "password");
Folder fldr = store.getFolder("Inbox");
fldr.open(Folder.READ_WRITE);
Message msgs[] = fldr.getMessages();
for(int i = 0 ; i < msgs.length ; i++) {
System.out.println(InternetAddress.toString(msgs[i].getFrom()) + "<-- FROM" + " " + msgs[i].getSubject() + "<---Subject");
}
} catch(Exception exc) {
exc.printStackTrace();
}
}
}
在运行时出现以下异常:
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
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 NewClass.main(NewClass.java:25)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at sun.security.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.mail.util.SocketFetcher.configureSSLSocket(SocketFetcher.java:507)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:238)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:107)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:261)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:206)
... 3 more
这是为什么呢? rediff 甚至免费提供其他客户端的 pop3 服务吗?
最佳答案
从表面上看,您正在尝试使用 SSL。端口 110 通常不用于 SSL 连接。
<小时/>编辑:看起来 rediff 确实支持 POP3:http://support.rediff.com/cgi-bin/support/printdetail.cgi?id=mail_1304.htm
删除您的 SSL 连接,应该没问题。
<小时/>进一步编辑:看起来 POP3 是一项高级功能,因此您的帐户可能无法使用:http://support.rediff.com/cgi-bin/support/printdetail.cgi?id=mail_1301.htm
您需要联系 rediff 进行设置。
关于java - 无法下载主题和发件人地址(rediff),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6816656/