Three ways to verify mailbox effectiveness:
Mode 1:
public static Boolean checkemail (String email) {
if (!email.matches () [\\w\\.\\-]+@ ([\\w\\-]+\\.) +[\\w\\-]+ ")) {
return false;
}
String host = "";
String hostName = Email.split ("@") [1];
record[] result = NULL;
SmtpClient client = new SmtpClient ();
try {
Find MX Records
Lookup lookup = new Lookup (hostName, type.mx);
Lookup.run ();
if (Lookup.getresult ()!= lookup.successful) {
return false;
} else {
result = Lookup.getanswers ();
}
Connecting to a Mailbox server
for (int i = 0; i < result.length; i++) {
Host = Result[i].getadditionalname (). toString ();
Client.connect (host);
if (! Smtpreply.ispositivecompletion (Client.getreplycode ()) {
Client.disconnect ();
Continue
} else {
Break
}
}
The following 2 items to fill out their own fast, effective mailbox
Client.login ("163.com");
Client.setsender ("sxgkwei@163.com");
Client.addrecipient (email);
if (= = Client.getreplycode ()) {
return true;
}
catch (Exception e) {
E.printstacktrace ();
finally {
try {
Client.disconnect ();
catch (IOException e) {
}
}
return false;
}
Jar support required in this way: Commons-net-2.2.jar,dnsjava-2.1.1.jar
Mode 2:
public static Boolean checkemail (String email) throws Exception {
if (!email.matches () [\\w\\.\\-]+@ ([\\w\\-]+\\.) +[\\w\\-]+ ")) {
return false;
}
Isemailresult result = Isemail.is_email_verbose (email, true);
Switch (result.getstate ()) {
Case OK:
return true;
Default
return false;
}
}