Verify email in Java

后端 未结 9 1464
长发绾君心
长发绾君心 2020-12-02 11:27

Is there any way to verify in Java code that an e-mail address is valid. By valid, I don\'t just mean that it\'s in the correct format (someone@domain.subdomain), but that\'

相关标签:
9条回答
  • 2020-12-02 11:50

    The only way you can be certain is by actually sending a mail and have it read.

    Let your registration process have a step that requires responding to information found only in the email. This is what others do.

    0 讨论(0)
  • 2020-12-02 11:57

    If you're using GWT, you can't use InternetAddress, and the pattern supplied by MBCook is pretty scary.

    Here is a less scary regex (might not be as accurate):

    public static boolean isValidEmail(String emailAddress) {
        return emailAddress.contains(" ") == false && emailAddress.matches(".+@.+\\.[a-z]+");
    }
    
    0 讨论(0)
  • 2020-12-02 12:02

    Without sending an email, it could be hard to get 100%, but if you do a DNS lookup on the host that should at least tell you that it is a viable destination system.

    0 讨论(0)
  • 2020-12-02 12:04

    You cannot really verify that an email exists, see my answer to a very similar question here: Email SMTP validator

    0 讨论(0)
  • 2020-12-02 12:04

    Apache commons provides an email validator class too, which you can use. Simply pass your email address as an argument to isValid method.

    0 讨论(0)
  • 2020-12-02 12:04

    Do a DNS lookup on the hostname to see if that exists. You could theoretically also initiate a connection to the mailserver and see if it tells you whether the recipient exists, but I think many servers pretend they know an address, then reject the email anyway.

    0 讨论(0)
提交回复
热议问题