aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Validity of an email address in Java program. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Validity of an email address in Java program." Watch "Validity of an email address in Java program." New topic
Author

Validity of an email address in Java program.

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Hi friends,

I am sending an email using JavaMail API. I would like to check the validity of email address which the user gives before forwarding it to the JavaMail API for sending an email.

Please do help me in validating an email address which the user provides either through JavaMail API OR through regular expressions.

Which method is more near to accurate or best ?

Thanks and Regards,
Sid.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Why? JavaMail will already throw an exception if you give it a malformed e-mail address. (That was what you meant by "valid", wasn't it?) I don't see why you need to reinvent that wheel.
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 266
Paul Clapham wrote:Why? JavaMail will already throw an exception if you give it a malformed e-mail address. (That was what you meant by "valid", wasn't it?) I don't see why you need to reinvent that wheel.



What I mean was that when I give an invalid email address abc@sdgdfg.cgrfg then the program validates the email address, gives an error message and gracefully exits the program AND not give a stacktrace in the console or log file.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18651
    
    8

Then you have to be much more careful about what you want. That isn't a malformed e-mail address, so what's wrong with it? I expect you know that "cgrfg" isn't a top-level domain, at least not this month it isn't. So let's suppose that you had "abc@sdgdfg.com". Is that valid? Why, or why not?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Validity of an email address in Java program.