views:

45

answers:

2

Our website sends e-mails to the e-mail address which a user enters on our website. Some people enter garbage e-mail addresses. How can we find out, whether at least the host of the entered address is a valid one? Simply trying to open a socket at port 25 of the entered host?

Update: I've found a Java library for DNS stuff. What record should I check?

+1  A: 

You need to look up the MX record for the host-part from DNS...but there are many corner-cases. Don't reinvent the wheel (you're bound to get it wrong), try to find an existing library. I only know the one from Snertsoft for C (integrated into the commercial milter-sender), though.

[Disclaimer: I'm a happy user of milter-sender]

[Edit] Take a look at RFC 5321 Sec.5, which describes the rules for looking up the right host.

ShiDoiSi
A: 

I hope you are verifying (using a regular expression) that a valid e-mail address was entered. Otherwise, there is no point in checking whether the host is valid.

Bernard
Thats a nice bag of worms right there... http://www.regular-expressions.info/email.htmlWhy not just make the email address optional, if users don't want to provide one then they don't have to, if they do want to provide one make them enter it twice and validate both values match.
Jon Freedman
Sorry, this is not what I want. I want to prevent something like `[email protected]`.
mklhmnn