File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes how to handle wrong to mail address while sending email. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "how to handle wrong to mail address while sending email. " Watch "how to handle wrong to mail address while sending email. " New topic
Author

how to handle wrong to mail address while sending email.

ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
How to validate SMTP check while sending an Email.



if we give "abc@gmail111.com" then it is showing exception "Wrong To Mail address." but if we give "abc@gmail.com" then it is not giving any exception and it shows mail send. but is is non existing mail id. so can you please tell me how to validate SMTP check
i have a code for this validation but that one is in .NET

http://www.coveryourasp.com/ValidateEmail.asp#Result3

http://www.coveryourasp.com/ShowSource.asp?page=ValidateEmail

please reply.

Thanks,
-Ravi.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

The code on that link does not work. If I try somethingthatreallydoesnotexist@somedomain.com (a valid domain) it says that it passed the SMTP test.

The reason is clear: SMTP servers are not required to give any information on whether or not an email address exists at that server.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41830
    
  63
If the mail server doesn't exist (as I assume would be the case for gmail111.com) then that's detected right away because no network connection can be established. But for most other problems (non-existing account, closed account, account full, account temporarily unavailable etc.) the target mail server may accept the mail at first, and then bounce it later. So the "From" (or "Reply-To") address should be prepared to receive bounces that indicate failures, and handle those appropriately.


Ping & DNS - my free Android networking tools app
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23
thanks for reply ...

i got reply from postmaster@gmail.com but is there is any other way to handle that one. because what i am doing is, is exception occurred while sending email then i am storing that mail in EMP_EMAIL table is exception occur while sending email. then status will be E (Error). and is sent successfully then status will be "S"
and if the status is E then i am allowing registry user to re-send that mail. but as i am not getting any exception then it is inserting status as sent even if that one is non-existing mail id.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41830
    
  63
You could set up a background thread that periodically connects to the sending mail account, and which scans all incoming mails for failures. It can then change the DB records as appropriate. Note that bounces can take days to arrive. And since email is not a guaranteed delivery medium, you can never be sure that a mail actually got delivered (for example, the server may decide that it's spam and delete a mail without notifying anyone).

The bottom line is: Just because a mail was sent does not mean that it got delivered to the intended recipient. Often you'll receive a bounce mail when it did NOT get delivered, but you can't be sure of that. Even if you do get one, it can take days to arrive. You'll need to make allowances for all of this.
ravi pardeshi
Greenhorn

Joined: Jan 13, 2009
Posts: 23

but that solution doesn't sound very good..
let it be as earlier one..
registry user can send it via mail box.

Thanks you all.

have a nice day

Thanks,
-Ravi
Vikas Nahar
Greenhorn

Joined: Mar 01, 2010
Posts: 4
The link should solve your issues.

http://www.rgagnon.com/javadetails/java-0452.html

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

No it won't. It can test if a mail server is running, but not if a user exists on that mail server.
Vikas Nahar
Greenhorn

Joined: Mar 01, 2010
Posts: 4
Hi Rob,

It might work. I have not tested it personally because my ISP provider has blocked port 25. But I have seen similar scripts (using the same logic as the Java code) in ASP and PHP which are running and are available on websites to test email ids. I wanted to test the script myself and tried it on Google App engine but they do not support some of the Socket programming and I also tried on a server from godaddy.com but had some security issues so it did not work. Will try to contact my ISP and get port 25 unblocked for a few days and test the code.

Regards
Vikas Nahar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

If you read the document linked to, you will see a long list of reasons why an attempt to find whether a specific e-mail address exists on a server might fail. Not mentioned is the common occurrence that an e-mail address exists, but nobody ever reads messages sent to it.

Basically this approach is a dead end. Servers don't want to expose their user lists, because of the obvious risk of spam, and they are going to take more and better measures to prevent you from getting them. So don't take the spammer approach. Really you don't need to know in advance if an e-mail address exists, do you? If you're having a problem with that then you ought to take a second look at your system design to see why people are giving you bogus addresses.
Vikas Nahar
Greenhorn

Joined: Mar 01, 2010
Posts: 4
Hi Paul,

I agree with you. But the my friend wanted to check email ids of employees of different companies and when we checked such email ids with php and asp script it did work. The cases where it failed were like yahoo.com and in some cases for gmail.com as well. But it did work with my university email server and my friends companies mail server. You may check it on the following link.

http://www.coveryourasp.com/ValidateEmail.asp#Result3


Regards
Vikas Nahar
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

I'm not interested in checking that link. I've already said that I believe aggressive validation of e-mail addresses is a bad practice, so I don't care that it can sometimes be done.
Mosh Shaikh
Greenhorn

Joined: Jul 02, 2013
Posts: 1


The above code should precisely list down all the invalid and valid email addresses.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

No it won't, because an invalid email address doesn't have to cause an exception while sending.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to handle wrong to mail address while sending email.