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?

解决方案

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

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

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.

And, as Jordan Stewart kindly appointed:

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值