如何从Java检查SMTP服务器的状态? [英] How to check status of an SMTP server from Java?

查看:368
本文介绍了如何从Java检查SMTP服务器的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In a Java program, what is the best way of determining if an SMTP server is ready to accept and send an email?

推荐答案

您可以使用 JavaMail API ,然后尝试发送电子邮件.

You can use JavaMail API and try to send an email.

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

If you don't want to actually send the email, you can open a TCP socket to port number 25 of your mail server and send the following commands:

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

确保在每个命令发出后检查所有服务器响应.如果到那时为止您都没有看到任何错误,则可能可以使用该SMTP服务器发送电子邮件.

Make sure you check all server responses after each command issued. If you don't see any errors until that point, then probably you will be able to send emails with that SMTP server.

乔丹·斯图尔特(Jordan Stewart)友好地任命:

And, as Jordan Stewart kindly appointed:

您还需要确保 HELO域具有互补的A/ PTR dns记录对,带有IP 域映射到的地址 您连接的IP地址. 该域还至少需要一个MX 记录. IE.如果您使用的是服务器 从连接是123.45.67.89然后 您需要一个A记录映射 yourdomain.com到123.45.67.89和一个 PTR(反向DNS")记录映射 123.45.67.89回到yourdomain.com.如果不满足这些条件中的任何一个 你会遇到一些问题 邮件服务器作为这些检查 都是反垃圾邮件措施.

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检查SMTP服务器的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆