Java's real, validated examples of email mailboxes

Source: Internet
Author: User
Tags smtpclient

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;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.