如何验证SMTP服务器 [英] How to validate SMTP server
问题描述
我工作的一个项目,我要验证在一个文本框的用户将提供详细的给SMTP服务器即,然后他会点击测试按钮。我要检查用户输入的服务器是否是SMTP服务器或不?
I am working on a project where I have to validate the given SMTP server i.e in a textbox user will provide the detail and then he will click on a test button. I want to check whether the server entered by the user is an Smtp Server or not?
任何想法??
推荐答案
尝试连接到SMTP端口,并确保你得到一条直线从回来的开头220,并包含字母SMTP。一个典型的例子回应是:
Attempt to connect to the SMTP port, and ensure you get a line back from it that starts with "220 " and contains the letters "SMTP". A typical example response would be:
220 prod.monadic.cynic.net ESMTP Postfix (2.5.5)
然后礼貌和发送退出
\r\ N,挂断电话。
Then be polite and send "QUIT
\r\n" to hang up.
您可以做一些进一步的测试,如果你喜欢,比如测试,用户可能可以传递消息。对于这一点,你会使用用户的电子邮件地址发送一个HELO命令将主机名(或任何字符串,真的),一个 MAIL FROM
命令和 RCPT TO:< example@example.com>
。在这一点上,大多数服务器会告诉你,如果不允许中继。 (我假设你从你以后将发送邮件的计算机做这个。)所以只要你退出
之后,而不是发出 DATA
命令和
消息数据,什么都不会被发送。
You can do some further testing, if you like, such as testing that the user can likely deliver messages. For this, you'd send a HELO command with your hostname (or any string, really), a MAIL FROM
command using the user's e-mail address, and a RCPT TO:<example@example.com>
. Most servers at that point will tell you if relaying is not allowed. (I'm assuming you're doing this from the computer from which you will later be sending mail.) So long as you QUIT
after that, rather than issuing a DATA
command and
the message data, nothing will be sent.
下面是一个例子会话,从做外壳采用了netcat的命令,显示出我的服务器存在,但是从随机IP地址的人都不会转发邮件。
Here's an example session, done from the shell using the "netcat" command, showing that my server exists, but will not relay mail for people from random IP addresses.
$ nc prod.monadic.cynic.net. 25
220 prod.monadic.cynic.net ESMTP Postfix (2.5.5)
HELO cynic.net
250 prod.monadic.cynic.net
MAIL FROM:<cjs@cynic.net>
250 2.1.0 Ok
RCPT TO:<example@example.com>
554 5.7.1 <example@example.com>: Relay access denied
QUIT
221 2.0.0 Bye
$
这篇关于如何验证SMTP服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!