Java, send e-mail: verify whether valid host is provided in e-mail address
-
29-09-2019 - |
문제
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?
해결책
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.
다른 팁
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.