我已經編寫代碼來檢查它正在爲gmail工作的電子郵件帳戶& yahoo郵件 但它不適用於hotmail &美國在線。以下是我用過的代碼。如果有任何想法,請幫助。如何檢查電子郵件帳戶是否有效?
我得到以下情況例外,當我通過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;
}
}
只需發送一封電子郵件並等待,直到您得到他們的回覆:P – GoodSp33d 2010-09-21 07:40:05
您是否確實想直接連接到Hotmail/AOL?也許問題是,Hotmail/AOL不希望你檢查這樣的電子郵件地址... – 2010-09-21 07:51:53