gpt4 book ai didi

java - 如何从 Java 检查 SMTP 服务器的状态?

转载 作者:行者123 更新时间:2023-12-01 19:25:06 27 4
gpt4 key购买 nike

在 Java 程序中,确定 SMTP 服务器是否准备好接受和发送电子邮件的最佳方法是什么?

最佳答案

您可以使用JavaMail API并尝试发送电子邮件。

如果您不想实际发送电子邮件,您可以打开到邮件服务器端口号 25 的 TCP 套接字并发送以下命令:

HELO yourdomain.com
MAIL FROM: youremail@yourdomain.com
RCPT TO: recipient@recipientdomain.com

确保在发出每个命令后检查所有服务器响应。如果在此之前您没有看到任何错误,那么您可能可以使用该 SMTP 服务器发送电子邮件。

并且,正如乔丹·斯图尔特亲切指定的那样:

You'll also want to make sure that the HELO domain has a complementary A / PTR dns record pair, with the IP address the domain is mapped to being the IP address you're connecting from. The domain also needs at least one MX record. I.e. if the server you're connecting from is 123.45.67.89 then you'd need an A record mapping yourdomain.com to 123.45.67.89 and a PTR ("reverse DNS") record mapping 123.45.67.89 back to yourdomain.com. If any of these conditions aren't met you'll run into problems with some mail servers as checks for these things are anti-spam measures.

关于java - 如何从 Java 检查 SMTP 服务器的状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1704749/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com