The following code is a sample of some characters you can check are in an email address, or should not be in an email address. It is not a complete email validation program that checks for all possible email scenarios, but can be added to as needed.

/*
* Checks for invalid characters
* in email addresses
*/
public class EmailValidation {
   public static void main(String[] args)
                                 throws Exception {

      String input = "@sun.com";
      //Checks for email addresses starting with
      //inappropriate symbols like dots or @ signs.
      Pattern p = Pattern.compile("^\\.|^\\@");
      Matcher m = p.matcher(input);
      if (m.find())
         System.err.println("Email addresses don't start" +
                            " with dots or @ signs.");
      //Checks for email addresses that start with
      //www. and prints a message if it does.
      p = Pattern.compile("^www\\.");
      m = p.matcher(input);
      if (m.find()) {
        System.out.println("Email addresses don't start" +
                " with \"www.\", only web pages do.");
      }
      p = Pattern.compile("[^A-Za-z0-9\\.\\@_\\-~#]+");
      m = p.matcher(input);
      StringBuffer sb = new StringBuffer();
      boolean result = m.find();
      boolean deletedIllegalChars = false;

      while(result) {
         deletedIllegalChars = true;
         m.appendReplacement(sb, "");
         result = m.find();
      }

      // Add the last segment of input to the new String
      m.appendTail(sb);

      input = sb.toString();

      if (deletedIllegalChars) {
         System.out.println("It contained incorrect characters" +
                           " , such as spaces or commas.");
      }
   }
}
 

Regards,
Vikramjit Singh,
GTL Ltd.
Ph. (022) 7612929-1059

-----Original Message-----
From: ssmtech [mailto:[EMAIL PROTECTED]]
Sent: Friday, October 11, 2002 3:52 AM
To: [EMAIL PROTECTED]
Subject: Validating Email Address

Hello All,
          I am using JavaMail API to send thousands of emails every day through my application running on J2EE application server...
But what i really want to do is, how do i check whether a particular Email Address is Valid or not,if not valid then catch a exception and report it....
Also i meant by Valid email address as to be exsisting on that mail server..e.g "[EMAIL PROTECTED]" .i.e.the user "javamail" should exist on that domain "sun.com"...
 
Is there any way which i can do the above thing?
Also,since i will be sending 1000's of emails every day will it be feasible for me to check each and every email whether it exist or not and then send it.....how much time will it take to do the same...
 

Please help me out with this,can anybody give me a Detail desciption and Code of how can i do it...
 
Any suggestions are greatly appreciated
 
Thanks a million is advance
 
Sam

Disclaimer: This e-mail message along with any attachments is intended only for the addressee and may contain confidential and privileged information of GTL Limited. If the reader of this message is not the intended recipient, you are notified that any dissemination, distribution or copy of this communication is strictly prohibited. If you have received this message by error, please notify us immediately, return the original mail to the sender and delete the message from your system.

Reply via email to