• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Catching invalid email Id exception

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We are doing a project where we send mails to the ID entered by the user.
We need to catch an exception when the mail id in the "TO" field is
invalid.

We have written the following code:



The code is supposed to catch MessagingException when the mail ID is invalid (i.e the format of mail Id is correct, but email id does not exist like abc@yahoo). But it does not catch any exceptions and returns 1.

Please let me know what are we doing wrong?

Thanks in advance,

Vinayak
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand -- where do you think the exception will come from? The JavaMail API has no way to find out if an email address is "real" except by attempting to deliver the message. Even if the message is accepted by the local MTA, that's no assurance that it won't eventually be rejected. Finding out whether a given email address is valid is, in the general case, a tough problem, and JavaMail isn't going to just hand you the answer.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


The code is supposed to catch MessagingException when the mail ID is invalid (i.e the format of mail Id is correct, but email id does not exist like abc@yahoo). But it does not catch any exceptions and returns 1.



A common practice in simple validation of e-mail is to ensure that there exists a . character after an '@' so is it very easy to check that abc@yahoo is invalid. Although checking abc@yahoo.cim is invalid is much harder for reasons all ready listed. Even if a mail address is valid at the time of sending it may be deleted and become invalid before it is delivered since messaging is inherently asynchronus.
 
Vinayak patil
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We had written a code, that got us the following:

It is part of the printstacktrace.



Wrong To address
-----------------
javax.servlet.ServletException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for vinayak.n.patil@abc.com

Root Cause
----------
javax.mail.SendFailedException: Sending failed;
nested exception is:
javax.mail.SendFailedException: Invalid Addresses;
nested exception is:
javax.mail.SendFailedException: 550 5.7.1 Unable to relay for vinayak.n.patil@abc.com


Earlier we used to get this exception. We changed the code and are not getting the above result. We are not able to track the changes and so are unable to point the exact error.

-Vinayak
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you're not getting any error now, you need to do some more investigation but I did find one post about this on Sun's forums that suggested the problem is with the SMTP server you are sending with:

Sun Forum link
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's been a while since I worked with javax.mail, but I note that Transport allows you to addTransportListener() - it looks like this is supposed to provide notification in case of delivery failure. I suspect it is not guaranteed, since for many types of delivery failure it would have to depend on the receiving server to send a bounce message in some standard format; I don't believe you can be sure this will happen. But it's probably worthwhile to try registering a listener to see what notifications you can receive.

SendFailedException and related issues are also dicussed in Sun's JavaMail FAQ. Good luck.
[ October 25, 2005: Message edited by: Jim Yingst ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic