【小蜗牛闲情之作
 
在“资源很匮乏”的时候,没有可视化的MUA可以使用,比如Foxmail,Outlook,Thunderbird等,为了紧急发送一封邮件,可以使用“万能”的telnet哦。
 
其实用telnet来收发邮件,是一种非常高效的检测手段,常常用来检测邮件服务器是否正常等。下面举个实例来简单说说如何用telnet来发一封英文email。
 
【注意】下面的粉红色粗体为telnet和MTA会话过程中用户的输入
 
1、不需要SMTP验证的情况

[root@pps htdocs]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 pps.hoho.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 24 Mar 2009 23:57:45 +0800
helo localhost
250-pps.hoho.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
mail from:<[email]hoho@hoho.com[/email]>
250 2.1.0 <[email]hoho@hoho.com[/email]>... Sender ok
rcpt to:<[email]zhaozh@hoho.com[/email]>
250 2.1.5 <[email]zhaozh@hoho.com[/email]>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
subject:Hi
Just say Hi to you.
.

250 2.0.0 n2OFvjJI010833 Message accepted for delivery
quit
221 2.0.0 pps.hoho.com closing connection
Connection closed by foreign host.
 
这里,我发了一封主题为"Hi",内容为"Just say Hi to you."的简单英文邮件。在telnet里输入的时候,根据提示"354 Enter mail, end with "." on a line by itself",需要输入一行只有一个"."的行来结束邮件主体输入,然后输入"quit"结束和MTA的会话。
 
2、需要SMTP验证的情况
 
如果MTA需要SMTP验证,则在MAIL FROM时候会提示你服务器需要SMTP验证,或者客户端可以使用EHLO命令,看看服务器是否需要验证,如果知道服务器需要验证,则EHLO之后就AUTH,如下:
 
[root@pps htdocs]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 pps.hoho.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 24 Mar 2009 23:57:45 +0800
ehlo localhost
250-pps.hoho.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-AUTH LOGIN PLAIN
250-DELIVERBY
250 HELP
auth login
334 VXNlcm5hbWU6
c25haWw=
334 UGFzc3dvcmQ6
c25haWx3YXJyaW9y
235 2.0.0 OK Authenticated
mail from:<[email]hoho@hoho.com[/email]>
250 2.1.0 <[email]hoho@hoho.com[/email]>... Sender ok
rcpt to:<[email]zhaozh@hoho.com[/email]>
250 2.1.5 <[email]zhaozh@hoho.com[/email]>... Recipient ok
data
354 Enter mail, end with "." on a line by itself
subject:Hi
Just say Hi to you.
.

250 2.0.0 n2OFvjJI010833 Message accepted for delivery
quit
221 2.0.0 pps.hoho.com closing connection
Connection closed by foreign host.
 
这里使用LOGIN方式来验证,需要输入base64编码格式的用户名和密码。可以参考我在一篇文章里说的使用PHP的base64编解码函数来轻松实现字符串编解码,也可以使用我在另一篇文章说的使用Linux系统的实用工具base64命令来实现,当然也可以使用你自己熟悉的其它办法。
 
我输入的用户名是snail,密码是snailwarrior:
334 VXNlcm5hbWU6      --> 334 Username:
c25haWw=                --> snail
334 UGFzc3dvcmQ6      --> 334 Password:
c25haWx3YXJyaW9y  --> snailwarrior
 
------------------------------------------------------------------------------------------
赵小蜗牛
QQ: 755721501
在不断奉献中谋求生存发展、打造自己的优秀品质,用人性最本质最动人的一面“营销”自己!