我已经编写了代码来检查它为gmail&雅虎邮箱 但它不适用于hotmail& AOL。以下是我使用过的代码。如果有任何想法请帮助。
我通过hotmail帐户时遇到以下异常:
javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
代码:
public boolean checkEmailAccountInfo(final String userMailID,
final String password, String outgoingMailServer, String portNo) {
try {
Properties p = new Properties();
// Boolean b = new Boolean(true);
p.put("mail.smtps.auth", true);
p.put("mail.smtp.user", userMailID);
p.put("mail.smtp.host", outgoingMailServer);
p.put("mail.smtp.port", portNo);
p.put("mail.smtp.starttls.enable", true);
p.put("mail.smtp.auth", "true");
p.put("mail.smtp.8BITMIME", "true");
p.put("mail.smtp.PIPELINING", "true");
p.put("mail.smtp.socketFactory.port", 465);
p.put("mail.smtp.debug", "true");
p.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
p.put("mail.smtp.socketFactory.fallback", "false");
// create some properties and get the default Session
javax.mail.Session session = javax.mail.Session.getInstance(p,
new javax.mail.Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userMailID,
password);
}
});
session.setDebug(false);
Transport t = session.getTransport("smtp");
t.connect();
boolean isConnected = t.isConnected();
if (isConnected) {
t.close();
return true;
}
return false;
} catch (Exception e) {
return false;
}
}
答案 0 :(得分:1)
你可以试试这个:
p.put("mail.smtp.socketFactory.port", portNo);
这样可行。我已经使用其他邮件ID进行了测试。