views:

543

answers:

5

Is it possible to check whether an email is a valid email or not?

For checking whether a link is a valid one or not I am checking like this...

URL url = new URL("http://www.google.com");
URLConnection connection = url.openConnection();

  if ( connection instanceof HttpURLConnection)
  {
   HttpURLConnection httpConnection = (HttpURLConnection)connection;
   httpConnection.connect();
   return httpConnection.getResponseCode();
  }

now if its a mialto how do I do it?
URL url = new new URL("mailto:[email protected]");

A: 

To validate whether an email address is valid or not, you can read http://azcarya.blogspot.com/2007/10/email-address-validation.html. To check whether an email address exists or not, you can shoot an email to the address and check for the server reply, in case you receive an email address not valid status mail.

Sandy
+2  A: 

The answer is not really Java related, the short form is: you can't without actually sending an email to that address. See my answer to a similar question here: http://stackoverflow.com/questions/27474/email-smtp-validator

WMR
Also see: http://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email
Jonik
A: 

this smells. why would you want to do this? validate e-mails of your customers when they sign up for your service and then you can be sure their email exists. but checking whether other peoples' email exists smells.

Peter Perháč
A: 

I do believe there is a reason why you can't ping an email-address. Spammers would love to have the opportunity;)

Email clients give you an option to not download pictures, and that's because that would allow the spammers to see that someone actually read the mail, and thus someone is using the address. Another way is to have a "don't send me more of this crap" button, when someone clicks it, you know it's a used address.

A: 

to check if email address is really an email address you could to

try{
    InternetAddress a = new InternetAddress("[email protected]");
    a.validate()
}catch(Exception e){
    //INVALID
}

to check wether email address exists is another story...

miceuz
note: javax.mail.internet.InternetAddress is a class from the JavaMail API: http://java.sun.com/products/javamail/
Carlos Heuberger