aspose file tools
The moose likes Other JSE/JEE APIs and the fly likes JavaMail: Checking for valid e-mail address Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Reply Bookmark "JavaMail: Checking for valid e-mail address" Watch "JavaMail: Checking for valid e-mail address" New topic
Author

JavaMail: Checking for valid e-mail address

Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
Hey fellas,

I need to check if a String is a valid e-mail address. Does the code bellow makes sense for you?



Tks


Tiago Fernandez
http://www.tiago182.spyw.com/
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

From the JavaMail API:

Parse the given sequence of addresses into InternetAddress objects. If strict is false, simple email addresses separated by spaces are also allowed. If strict is true, many (but not all) of the RFC822 syntax rules are enforced. In particular, even if strict is true, addresses composed of simple names (with no "@domain" part) are allowed. Such "illegal" addresses are not uncommon in real messages.

Non-strict parsing is typically used when parsing a list of mail addresses entered by a human. Strict parsing is typically used when parsing address headers in mail messages.


I would say that you method might work sometimes. A better method would be to use a Regular Expression somewhere between getting the email address and handing it to the JavaMail API. That way you ensure that all the addresses are correct as soon as possible.

Here is Sun's tutorial on RE's. If you have other RE questions the Java In General (Intermediate) is the most appropriate forum for those. Here is a recent post on that very topic.
[ July 01, 2004: Message edited by: Gregg Bolinger ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JavaMail: Checking for valid e-mail address
 
Similar Threads
JavaMail & Distribution Lists
Private Messages
sending mail to multiple receipients
JFormattedTextField in swings
indexof chek