• Post Reply Bookmark Topic Watch Topic
  • New Topic

Email Address Validation

 
bhuvan sundar
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ranchers,

I'm using SMTP in my java class to send mail. I need to verify/validate the email address entered by the user before sending a mail to that address.

Is there any way to validate the address which is out of the domain where my SMTP server exists?

Please help me ASAP...Thanks in advance
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am not sure if you found and answer...

Do you want to know if the address is well formed or the domain of the address is valid, i.e. exists, has an MX record, etc.?
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use a PERL script to check and parse DNS records. It would be great to know how to do that directly with Java. Maybe some naming class or some method in the URL tools.
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the DnsContextFactory to perform MX lookups. If you search for DnsContextFactory on java.sun.com you will find some pretty good examples. Start there. In the meantime here is a quick example of getting select records for an IP.




The NetworkInterface and InetAddress classes are usefull also. Look at the methods

InetAddress.getAllByName()
InetAddress.getByName()
InetAddress.isReachable()


Last but not least, you can use sockets to perfom whois lookups directly.
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok here is a quick and dirty validator. Gets the email string, validates it. If ok it returns the email if DNS lookup fails returns "<< email >>". Thus resetting the field. This is an AJAX call on the server so it isn't a real validator per see ala JSF or JSP style.



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!