精华内容
下载资源
问答
  • Java验证邮箱是否真实存在有效 要检测邮箱是否真实存在,必须了解两方面知识:1. MX记录,winodws的nslookup命令。查看学习2. SMTP协议,如何通过telnet发送邮件。查看学习有个网站可以校验,...
    Java验证邮箱是否真实存在有效
    要检测邮箱是否真实存在,必须了解两方面知识:
    1. MX记录,winodws的nslookup命令。查看学习
    2. SMTP协议,如何通过telnet发送邮件。查看学习

    有个网站可以校验,http://verify-email.org/, 不过一小时只允许验证10次。

    直接上代码:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    import java.io.IOException;

    import org.apache.commons.net.smtp.SMTPClient;
    import org.apache.commons.net.smtp.SMTPReply;
    import org.xbill.DNS.Lookup;
    import org.xbill.DNS.Record;
    import org.xbill.DNS.Type;

    public class CheckEmailObj {
    public static boolean checkEmail(String email) {
    if (!email.matches("[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+")) {
    System.err.println("Format error");
    return false;
    }

    String log = "";
    String host = "";
    String hostName = email.split("@")[1];
    Record[] result = null;
    SMTPClient client = new SMTPClient();

    try {
    // 查找MX记录
    Lookup lookup = new Lookup(hostName, Type.MX);
    lookup.run();
    if (lookup.getResult() != Lookup.SUCCESSFUL) {
    log += "找不到MX记录\n";
    return false;
    } else {
    result = lookup.getAnswers();
    }

    // 连接到邮箱服务器
    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 {
    log += "MX record about " + hostName + " exists.\n";
    log += "Connection succeeded to " + host + "\n";
    break;
    }
    }
    log += client.getReplyString();

    // HELO cyou-inc.com
    client.login("cyou-inc.com");
    log += ">HELO cyou-inc.com\n";
    log += "=" + client.getReplyString();

    // MAIL FROM: <zhaojinglun@cyou-inc.com>
    client.setSender("zhaojinglun@cyou-inc.com");
    log += ">MAIL FROM: <zhaojinglun@cyou-inc.com>\n";
    log += "=" + client.getReplyString();

    // RCPT TO: <$email>
    client.addRecipient(email);
    log += ">RCPT TO: <" + email + ">\n";
    log += "=" + client.getReplyString();

    if (250 == client.getReplyCode()) {
    return true;
    }
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    try {
    client.disconnect();
    } catch (IOException e) {
    }
    // 打印日志
    System.err.println(log);
    }
    return false;
    }

    public static void main(String[] args) {
    System.err.println("Outcome: "
    + CheckEmailObj.checkEmail("pandajj0703@gmail.com"));
    }
    }
    import java.io.IOException; import org.apache.commons.net.smtp.SMTPClient; import org.apache.commons.net.smtp.SMTPReply; import org.xbill.DNS.Lookup; import org.xbill.DNS.Record; import org.xbill.DNS.Type; public class CheckEmailObj { public static boolean checkEmail(String email) { if (!email.matches("[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+")) { System.err.println("Format error"); return false; } String log = ""; String host = ""; String hostName = email.split("@")[1]; Record[] result = null; SMTPClient client = new SMTPClient(); try { // 查找MX记录 Lookup lookup = new Lookup(hostName, Type.MX); lookup.run(); if (lookup.getResult() != Lookup.SUCCESSFUL) { log += "找不到MX记录\n"; return false; } else { result = lookup.getAnswers(); } // 连接到邮箱服务器 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 { log += "MX record about " + hostName + " exists.\n"; log += "Connection succeeded to " + host + "\n"; break; } } log += client.getReplyString(); // HELO cyou-inc.com client.login("cyou-inc.com"); log += ">HELO cyou-inc.com\n"; log += "=" + client.getReplyString(); // MAIL FROM: <zhaojinglun@cyou-inc.com> client.setSender("zhaojinglun@cyou-inc.com"); log += ">MAIL FROM: <zhaojinglun@cyou-inc.com>\n"; log += "=" + client.getReplyString(); // RCPT TO: <$email> client.addRecipient(email); log += ">RCPT TO: <" + email + ">\n"; log += "=" + client.getReplyString(); if (250 == client.getReplyCode()) { return true; } } catch (Exception e) { e.printStackTrace(); } finally { try { client.disconnect(); } catch (IOException e) { } // 打印日志 System.err.println(log); } return false; } public static void main(String[] args) { System.err.println("Outcome: " + CheckEmailObj.checkEmail("pandajj0703@gmail.com")); } }

    需要的两个jar包:
    http://www.dnsjava.org/download/ 
    http://apache.etoak.com /commons/net/binaries/commons-net-2.0.zip

    执行结果:
    MX record about gmail.com exists.
    Connection succeeded to alt2.gmail-smtp-in.l.google.com.
    220 mx.google.com ESMTP p37si6502151gvf.9
    >HELO cyou-inc.com
    =250 mx.google.com at your service
    >MAIL FROM: <zhaojinglun@cyou-inc.com>
    =250 2.1.0 OK p37si6502151gvf.9
    >RCPT TO: <pandajj0703@gmail.com>
    =250 2.1.5 OK p37si6502151gvf.9

    Outcome: true


    或者通过webservice实现:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    import java.io.PrintWriter;
    import java.net.URL;
    import java.net.URLConnection;

    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;

    import org.w3c.dom.Document;

    public class CheckEmailWS {
    public static boolean checkEmail(String email) {
    String soapRequestData = ""
    + "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">"
    + " <soap:Body>"
    + " <IsValidEmail xmlns=\"http://www.webservicex.net\">"
    + " <Email>" + email + "</Email>" + " </IsValidEmail>"
    + " </soap:Body>" + "</soap:Envelope>";

    try {
    URL u = new URL(
    "http://www.webservicex.net/ValidateEmail.asmx?op=IsValidEmail");
    URLConnection uc = u.openConnection();
    uc.setDoOutput(true);
    uc.setRequestProperty("Content-Type",
    "application/soap+xml; charset=utf-8");
    PrintWriter pw = new PrintWriter(uc.getOutputStream());
    pw.println(soapRequestData);
    pw.close();

    DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = bf.newDocumentBuilder();
    Document document = db.parse(uc.getInputStream());

    String res = document.getElementsByTagName("IsValidEmailResult")
    .item(0).getTextContent();

    return Boolean.parseBoolean(res);
    } catch (Exception e) {
    e.printStackTrace();
    return false;
    }
    }
    展开全文
  • java 验证邮箱

    2011-10-29 00:39:31
    java 验证邮箱格式正确性(转载) Java 正则表达式   public class RegisterCheck { /** * 验证输入的邮箱格式是否符合 * @param email * @return 是否合法 */ public static boolean...

    java 验证邮箱格式正确性(转载)

     

    public class RegisterCheck {
        /**
         * 验证输入的邮箱格式是否符合
         * @param email
         * @return 是否合法
         */
    public static boolean emailFormat(String email)
        {
            boolean tag = true;
            final String pattern1 = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            final Pattern pattern = Pattern.compile(pattern1);
            final Matcher mat = pattern.matcher(email);
            if (!mat.find()) {
                tag = false;
            }
            return tag;
        }
    }

     

     

     

        private static boolean getEmail(String line){
            Pattern p = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
            Matcher m = p.matcher(line);
            return m.find();
        }
     

     

    展开全文
  • java验证邮箱,电话,IP

    2012-09-26 17:28:04
    java 验证邮箱 验证电话 验证IP ..复制代码即可用
  • java验证邮箱

    千次阅读 2018-11-09 11:48:55
    import java.util.regex.Matcher; import java.util.regex.Pattern; public static boolean checkEmail(String email) { boolean flag = false; try { String check = "^([a-z0-9A-Z]+[-|_|\\...
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    
    public static boolean checkEmail(String email) {
    	    boolean flag = false;
    	    try {
    	        String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
    	        Pattern regex = Pattern.compile(check);
    	        Matcher matcher = regex.matcher(email);
    	        flag = matcher.matches();
    	    } catch (Exception e) {
    	        flag = false;
    	    }
    	    return flag;
    	}

     

    展开全文
  • java邮箱验证

    2019-08-26 21:16:24
    java邮箱验证功能: 1.前台页面注册 2.成功发送验证邮件 3.点击邮件进行验证
  • java验证邮箱地址是否正确

    千次阅读 2017-08-24 10:24:05
    * 验证邮箱 * * @param email * @return */ public static boolean checkEmail(String email) { boolean flag = false; try { String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9
    /**
     * 验证邮箱
     *
     * @param email
     * @return
     */
    public static boolean checkEmail(String email) {
        boolean flag = false;
        try {
            String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
            Pattern regex = Pattern.compile(check);
            Matcher matcher = regex.matcher(email);
            flag = matcher.matches();
        } catch (Exception e) {
            flag = false;
        }
        return flag;
    }
    展开全文
  • JAVA 邮箱验证

    2019-02-26 10:36:21
    JAVA 邮箱验证两种方式 据我所知,java邮箱验证有两种方式,验证码、链接 这两种方式都涉及到发送邮件,首先实现发送邮件功能 首先申请邮箱号码,QQ号码要去申请发送邮件功能,这个步骤我就不具体说了, ...
  • java激活邮箱验证资料

    2018-12-17 10:16:21
    java激活邮箱验证功能,就是现如今注册网站时,需要激活邮箱验证的这个功能。
  • 和普通的正则表达式不同,他要求尝试链接目标邮箱服务器并请求校验目标邮箱是否存在。 先来了解    DNS之MX记录  对于DNS不了解的,请移步百度搜索。  DNS中除了A记录(域名-IP映射)之外,还有MX记录(邮件...
  • Java邮箱验证

    2018-12-13 10:28:12
    Java邮箱验证 引入jar包 activation.jar、mail.jar 或者在pom.xml文件中引入 &lt;!-- https://mvnrepository.com/artifact/javax.activation/activation --&gt; &lt;dependency&gt; &lt;...
  • java 验证邮箱格式正确性 import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegisterCheck { /** * 验证输入的邮箱格式是否符合 * @param email * @return 是否合法 */ ...
  • public static void main(String[] args) { // TODO Auto-generated method stub String email = "sdasdasdiasd"; boolean result = check1(email); System.out.print(result); //规则二:前缀最大8 ...
  • Java 正则验证邮箱

    万次阅读 2018-10-10 17:01:46
    做邮件的功能的时候难免会碰到邮箱验证,接下来我就把邮件的正则记录下来,方便以后查看。 Java方式: public static boolean isEmail(String email){ if (null==email || "".equals(email)){ ...
  • 思路:android端传送邮箱地址给后台,后台获取邮箱地址后,链接公司邮箱,并发送验证码邮件,并返回邮箱地址+验证码给Android端,Android进行验证邮箱地址和验证码是否匹配。直接上后台代码,已经写成工具类,注释...
  • java验证邮箱、数字

    2011-04-14 08:26:14
    ava 验证邮箱格式正确性 import java.util.regex.Matcher; import java.util.regex.Pattern; public class RegisterCheck { /** * 验证输入的邮箱格式是否符合 * @param email * @return 是否...
  • java 验证邮箱格式

    千次阅读 2017-06-07 15:48:22
     Pattern pattern=Pattern.compile("^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?...model.addAttribute("message", "邮箱格式错误");  return "register";  }
  • 一、java编写邮箱地址、邮箱验证 例如: 编写一个邮箱地址是否合法,如果合法则打印出用户名部分和该邮箱所属的网站域名,如果邮箱地址不合法则显示不合法的原因 温馨提示:邮箱地址不合法的因素: (1)邮箱地址中...
  • Java验证邮箱有效性和真实性

    万次阅读 热门讨论 2016-04-14 11:32:56
    Java验证邮箱是否真实存在有效 要检测邮箱是否真实存在,必须了解两方面知识: 1. MX记录,winodws的nslookup命令。查看学习 2. SMTP协议,如何通过telnet发送邮件。查看学习 有个网站可以校验,...
  • java验证邮箱地址是否合法

    千次阅读 2017-09-11 15:31:46
    设定邮箱地址的合法规则,合法邮箱地址要求如下: (1)字符必须是英文或数字开始 (2)必须包含一个 @ 和 . (3)@符号在 . 符号前面 (4)以英文或数字结尾 上代码: public class Test { public static ...
  • java 验证邮箱格式正确性 public class RegisterCheck {  /**  * 验证输入的邮箱格式是否符合  * @param email  * @return 是否合法  */ public static boolean emailFormat(String email)  {  ...
  • java中应用正则表达式判断邮箱格式,如果用户输入格式错误,提醒用户重新输入。若输入正确,直接执行。刚学JDBC,具体应该怎么写,真心求教?
  • Java验证邮箱(正则)

    2020-07-01 10:36:59
    验证邮箱 :\w+([-+.]\w+)@\w+([-.]\w+).\w+([-.]\w+)*
  • java判断邮箱是否存在.有返回值

    千次阅读 2016-03-21 16:14:05
    有时候需要判断该邮箱是否存在. public static boolean checkEmail(String email) {  if (!email.matches("[\\w\\.\\-]+@([\\w\\-]+\\.)+[\\w\\-]+")) {  return false;  }  String log = "";  ...
  • 主要介绍了Java注册邮箱激活验证实现代码,有需要的朋友可以参考一下
  • Java实现邮箱激活验证

    千次阅读 2016-07-08 09:51:35
    Java实现邮箱激活验证 RegisterValidateService.java   [java] view plaincopyprint? package com.app.service.impl;    import java.text.ParseException;  import java....

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 38,644
精华内容 15,457
关键字:

java验证邮箱是否存在

java 订阅