How to check whether the email account is valid?
I have already written code to check the email account it is working for gmail & yahoo mail but it is not working for hotmail & AOL. Below is the code I have used. If any idea please help.
I am getting following exception when I pass hotmail account:
javax.mail.MessagingException: Exception reading response;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
Code:
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 Passw开发者_如何学运维ordAuthentication(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;
}
}
You can try for this :
p.put("mail.smtp.socketFactory.port", portNo);
This will work .I have tested it with other mail ids.
精彩评论