如何用手动Telnet会话检查SMTP连接

如何用手动Telnet会话检查SMTP连接

如何用手动Telnet会话检查SMTP连接

Feb 7, 2020

出版商

出版商

Bird

Bird

-

类别

类别

电子邮件

电子邮件

Ready to see Bird
in action?

Ready to see Bird
in action?

How to Check an SMTP Connection with a Manual Telnet Session

In the world of email, there are many facets to testing, but one of the most basic tests you can do is to simply telnet into a given SMTP server.  This SMTP check is useful in determining if the most basic of problems do or do not exist.

  • 服务器启动了吗?

  • 是否有防火墙阻碍了通信?

  • 邮件服务器是否允许中转某个特定的域名/邮件地址?

  • 邮件服务器支持哪些SMTP命令?

  • 服务器是否以正确的主机名进行响应?

  • 连接是否在任何第三方软件或API之外工作?


所有这些问题以及更多的问题都可以通过一个简单的telnet测试来回答。

Before we get started, be sure to open up our companion piece to this post: 跳出的信息会被发送到哪里? in a new tab so you can read it after you’re done with this blog.

As a note, the commands used in the following examples (as well as additional commands) are covered in section 4.1 of RFC 2821.


如何使用Telnet发送电子邮件?

通过telnet发送电子邮件可以帮助你识别当前配置中的可传递性问题。


Before you send an email using telnet, confirm telnet is both installed and enabled on your computer. Most computers come pre-installed with a telnet client. For those Windows versions that do not, one can be installed by opening the “Programs and Features” section of the control panel and selecting “Turn Windows features on or off”. With this window open, select “telnet client” and then click OK.

一旦telnet客户端被确认安装在服务器上,打开终端窗口,你将在那里输入提示命令。在Windows上,使用Windows+R,键入 "cmd",然后按回车。对于Mac用户,你可以通过打开Finder并在应用程序页面上搜索 "实用工具",或在Launchpad搜索功能中输入 "终端 "来找到终端图标。

接下来,我们需要找到一个可以登录的邮件服务器。为此,我们将需要一个给定域名的DNS MX记录。这可以通过以下命令找到(在这些例子中,将使用port25.com,但任何域都可以替代)。

窗口。

nslookup -type=mx port25.com

非权威性的回答。

port25.com  MX preference = 100, mail exchanger = mail.port25.com

Linux。

nslookup -type=mx port25.com

非权威性的回答。

port25.com  mail exchanger = 100 mail.port25.com.


SMTP使用三个端口之一--25、465或587,Microsoft Outlook通常使用这些端口。如果你的SMTP中继使用的端口与例子中所示的25不同,你将使用邮件交换服务器对nslookup的响应所指定的端口。你也可以通过询问你的管理员或登录邮件交换服务器并查看协议来验证你的SMTP所依赖的端口。

Next we need the DNS PTR for the IP we are going to use.  First we need to know what IP address the internet sees us as having.  To find that we can use a website like:

http://whatismyipaddress.com/


用IP地址运行以下命令,其中A.B.C.D是IP地址。

窗口。

nslookup -type=ptr A.B.C.D

Non-authoritative answer: 

D.C.B.A.in-addr.arpa 名称 = server.example.com

Linux。

nslookup -type=ptr A.B.C.D

Non-authoritative answer: 

D.C.B.A.in-addr.arpa 名称 = server.example.com

server.example.com只是一个例子,你的结果会有所不同。

So now that we have the MX record for port25.com and the PTR for the IP we are going to use, it is time to log in 到 SMTP server.  To do so, use the following command:

telnet mail.port25.com 25

现在应该显示类似于以下的内容。

正在尝试 69.63.149.30...连接到 mail.port25.com (69.63.149.30)。转义字符为'^]'。 220 mail.port25.com (PowerMTA(TM) v4.0) ESMTP 服务准备就绪

如果你在这时收到类似 "无法连接 "的错误信息,要么是端口号正确,要么是邮件服务器遇到了问题。

ǞǞǞ first command we need to issue 到  mail server for our SMTP email tester is the EHLO  or HELO.  This is a basic greeting that starts the communication between the telnet client and the SMTP server.  Also passed is the DNS PTR for the IP address from which we are connecting as determined previously.

EHLO server.example.com

应该返回类似于以下的内容。

250-mail.port25.com说你好 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250-8BITMIME 250-XACK 250-XMRG 250-SIZE 54525952 250-VERP 250 DSN

This shows the SMTP commands that the SMTP server accepts.  Not all SMTP servers support the same sets of commands. For example, yahoo only shows the following:

250-8BITMIME 250-SIZE 41943040 250 PIPELINING

而AOL显示只有一个与。

250 DSN

ǞǞǞ next command we need to issue is the MAIL FROM command.  This determines the address to which bounces are sent. This is not the same as the from header, which is the email address shown in an email client.

MAIL FROM: <support@port25.com> 250 2.1.0 MAIL ok


确保你使用与你的邮件服务器的域相对应的域名。例如,如果你的电子邮件的域名是anycompany.com,你要使用you@anycompany.com,而不是像you@free-mail-provider.com 这样的外部电子邮件。域名的变化会导致错误信息的出现。


Now that the MAIL FROM  command has been sent we can send the RCPT TO  command.  This command tells the SMTP mail server to who the message should be sent. This can be the same or different than the to header, which is the email address shown in the email client.


RCPT TO: <support@port25.com> 250 2.1.5 <support@port25.com> ok

在发送RCPT TO命令之前,请仔细检查你的收件人地址 - 这里显示的错误信息可能表明电子邮件收件人拼写错误或被封锁。

The last command to run before starting the body of the message is the DATA  command.  This command lets the SMTP mail server know that everything else about to be sent is the body of the message (which also contains the headers).


DATA 354 发送信息

It is important to note that if a mail server supports PIPELINING, as mail.port25.com does, the SMTP mail server may wait until the DATA command is issued before responding to any other commands after the EHLO/HELO.  In this case, enter the MAIL FROM, RCPT TO, and DATA  commands before waiting for a response.


Now that the DATA command has been sent we can start sending the message contents.  This starts with the various headers. At minimum a message should contain a to, from, subject, and date header. The headers entered here will be shown to the user in their email client.


From: "John Smith" <jsmith@port25.com> To: "Jane Doe" <jdoe@port25.com> Subject: test message sent from manual telnet session Date: Wed, 11 May 2011 16:19:57 -0400

在标题设置好后,我们现在添加一个带有回车/换行的空行(只需按两次回车键),然后我们开始实际的信息正文。

世界你好,这是一个从手动telnet会话中发送的测试信息。你真正的,SMTP管理员

With the message complete, we need to tell the SMTP server that we are done with the message and want the SMTP mail server to accept it.  This is done with a period on a line by itself. If during the writing of a message a period on a line by itself is needed, you must put 2 periods, the first escaping the second.


.   250 2.6.0 message received

如果你收到的是错误信息,而不是 "已收到 "的通知,请记录相关细节,并联系你的电子邮件供应商以获得更多帮助。

Lastly, the QUIT  command is sent to close the connection:

QUIT 221 2.0.0 mail.port25.com说再见了

With that the mail server has now accepted the message for delivery, your telnet send email test is complete, and it should be sitting in the inbox of the RCPT TO address!!!

下面是所有的命令,没有中断。

telnet mail.port25.com 25 Trying 69.63.149.30... Connected to mail.port25.com (69.63.149.30). Escape character is '^]'. 220 mail.port25.com (PowerMTA(TM) v4.0) ESMTP service ready EHLO server.example.com 250-mail.port25.com says hello 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250-8BITMIME 250-XACK 250-XMRG 250-SIZE 54525952 250-VERP 250 DSN MAIL FROM: <support@port25.com> 250 2.1.0 MAIL ok RCPT TO: <support@port25.com> 250 2.1.5 <support@port25.com> ok DATA 354 send message From: "John Smith" <jsmith@port25.com> To: "Jane Doe" <jdoe@port25.com> Subject: test message sent from manual telnet session Date: Wed, 11 May 2011 16:19:57 -0400 Hello World, This is a test message sent from a manual telnet session. Yours truly, SMTP administrator . 250 2.6.0 message received QUIT 221 2.0.0 mail.port25.com says goodbye


使用telnet发送电子邮件可以让你快速测试连接能力,而且成本比强大的诊断设备或软件低。


如何使用Telnet认证测试SMTP?

现在你知道了如何用telnet检查SMTP连接,我们将讨论认证程序。SMTP认证有助于防止大量的垃圾邮件到达读者的收件箱,尽管不是所有的邮件交换服务器都需要它。


现代认证协议的主要区别是存在一个base64编码。Base64将二进制数据转换为邮件服务器所要求的ASCII文本格式,以便成功传输数据。这是一种将你的登录凭证--一些文本的组合--以计算机可以理解的数字格式表示的方法。

你可以使用软件或免费的在线工具生成你的base64。一旦你将信息传达给邮件服务器,它就会将这些数据与它的记录进行比较,以确定认证。


要通过telnet测试SMTP认证,请完成以下步骤。

  • 打开终端,使用telnet服务器名称和访问命令与邮件服务器连接 - 上面例子中的mail.port25.com。

  • Greet the server with EHLO or HELO, enter AUTH LOGIN, and wait for the computer’s response.

  • 输入base64编码的用户名并允许服务器回答。

  • 输入base64编码的密码,你应该收到诸如 "认证成功 "的回应。

  • 继续使用MAIL FROM、RCPT TO、DATA和QUIT来发送你的认证邮件。

Your new standard in Marketing, Pay & Sales. It's Bird

The right message -> to the right person ->right time.

By clicking "See Bird" you agree to Bird's 隐私声明.

Your new standard in Marketing, Pay & Sales. It's Bird

The right message -> to the right person ->right time.

By clicking "See Bird" you agree to Bird's 隐私声明.