Java,发送电子邮件:验证电子邮件地址中是否提供了有效的主机
我们的网站将电子邮件发送到用户在我们网站上输入的电子邮件地址。有些人输入垃圾电子邮件地址。我们怎样才能至少知道输入地址的主机是否有效?只是尝试在输入主机的端口 25 处打开套接字?
更新:我找到了一个 用于 DNS 内容的 Java 库。我应该检查什么记录?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要从 DNS 查找主机部分的 MX 记录...但有很多特殊情况。不要重新发明轮子(你一定会弄错),尝试找到一个现有的库。我只知道来自 Snertsoft for C 的一个(集成到商业 milter-sender ), 尽管。
[免责声明:我是 milter-sender 的快乐用户]
[编辑]
查看 RFC 5321 Sec.5,其中描述了规则用于查找合适的主机。
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.