SMTP(Simple Mail Transfer Protocol):简单邮件传输协议
邮件的发送,主要是通过SMTP协议来实现的
一、使用telnet客户端工具使用SMTP协议发送邮件
1、windows系统中启用telnet客户端工具
打开控制面板【右键左下角windows图标,点运行输入 control】,选择 程序 ==> 启用或关闭windows功能 ==> 找到 Telnet Client 勾选 ==> 点确定 启用telnet工具
2、使用 telnet 连接邮件服务器25端口
[root@17:10:48 ~]# telnet mail.domain.com 25 Trying 192.168.1.121... Connected to mail.domain.com. Escape character is '^]'. 220 mail.domain.com Anti-spam
3、使用EHLO指令与邮件服务器握手
1 [root@17:10:48 ~]# telnet mail.domain.com 25 2 Trying 192.168.1.121... 3 Connected to mail.domain.com. 4 Escape character is '^]'. 5 220 mail.domain.com Anti-spam 6 EHLO mail.domain.com 7 250-mail.domain.com 8 250-PIPELINING 9 250-SIZE 1024000000 10 250-VRFY 11 250-ETRN 12 250-AUTH PLAIN LOGIN 13 250-AUTH=PLAIN LOGIN 14 250-ENHANCEDSTATUSCODES 15 250-8BITMIME 16 250 DSN
4、使用AUTH LOGIN 来对自己的用户进行登陆,账号和密码需要经过 base64编码 之后输入
1 [root@17:10:48 ~]# telnet mail.domain.com 25 2 Trying 192.168.1.121... 3 Connected to mail.domain.com. 4 Escape character is '^]'. 5 220 mail.domain.com Anti-spam 6 EHLO mail.domain.com 7 250-mail.domain.com 8 250-PIPELINING 9 250-SIZE 1024000000 10 250-VRFY 11 250-ETRN 12 250-AUTH PLAIN LOGIN 13 250-AUTH=PLAIN LOGIN 14 250-ENHANCEDSTATUSCODES 15 250-8BITMIME 16 250 DSN 17 AUTH LOGIN 18 334 VXNlcm5hbWU6 19 aGFoYUBkb21haW4uY29tCg 20 334 UGFzc3dvcmQ6 21 MTIzNDU2Cg 22 235 2.7.0 Authentication successful
5、发送邮件
1 [root@17:10:48 ~]# telnet mail.domain.com 25 2 Trying 192.168.1.121... 3 Connected to mail.domain.com. 4 Escape character is '^]'. 5 220 mail.domain.com Anti-spam 6 EHLO mail.domain.com 7 250-mail.domain.com 8 250-PIPELINING 9 250-SIZE 1024000000 10 250-VRFY 11 250-ETRN 12 250-AUTH PLAIN LOGIN 13 250-AUTH=PLAIN LOGIN 14 250-ENHANCEDSTATUSCODES 15 250-8BITMIME 16 250 DSN 17 AUTH LOGIN 18 334 VXNlcm5hbWU6 19 aGFoYUBkb21haW4uY29tCg 20 334 UGFzc3dvcmQ6 21 MTIzNDU2Cg 22 235 2.7.0 Authentication successful 23 MAIL FROM: <haha@domain.com> 24 250 2.1.0 Ok 25 RCPT TO:<zcq@xxx.com> 26 250 2.1.5 Ok 27 DATA 28 354 End data with <CR><LF>.<CR><LF> 29 Date:12 Apr 1992 00:00:00 30 From: "测试邮件Telnet "<haha@domain.com> 31 To:<zcq@xxx.com> 32 Subject:Telnet发送的测试邮件,xxxxxx! 33 Content-type: text/plain;charset="gb2312" 34 Content-Transfer-Encoding: 7bit 35 36 来自旧时代的测试邮件。 37 38 39 . 40 250 2.0.0 Ok: queued as A76CA27B5 41 quit 42 221 2.0.0 Bye 43 Connection closed by foreign host.
6、登陆收件箱验证邮件,有可能被反垃圾程序隔离,没收到查下垃圾箱
二、常用SMTP命令
1、常用命令:
NOOP 测试发件服务器用,正常邮件服务器会返回 ok 应答
HELO 客户端为标识自己的身份而发送的命令(通常带域名) :HELO mail.domain.com
EHLO 使服务器可以表明自己支持扩展简单邮件传输协议(ESMTP)命令 : EHLO mail.domain.com
MAIL FROM 标识邮件的发件人: MAIL FROM: <haha@domain.com>
RCPT TO 标识邮件的收件人: RCPT TO: <xixi@test.com>
DATA 将命令之后的内容作为邮件数据传输给收件服务器,直到输入单行 点 . 为结束输入
RSET 重置会话,当前传输被取消
QUIT 终止会话
2、常见SMTP命令响应码
211 System status, or system help reply 【系统状态或系统帮助响应】
214 Help message 【帮助信息】
220 <domain> Service ready 【服务就绪】
221 <domain> Service closing transmission channel 【服务关闭】
250 Requested mail action okay, completed 【请求的邮件操作完成】
251 User not local; will forward to <forward-path> 【不是本地用户,将转发到 < 转发路径/地址 >】
354 Start mail input; end with <CRLF>.<CRLF> 【开始邮件输入,以回车 点 回车 结束】
421 <domain> Service not available, closing transmission channel 【服务不可用,关闭传输通道】
451 Requested action aborted: local error in processing 【请求的操作中止:处理过程中的本地错误】
452 Requested action not taken: insufficient system storage 【未采取的请求操作:系统存储不足】
455 Server unable to accommodate parameters 【服务器无法容纳参数】
500 Syntax error, command unrecognized (This may include errors such as command line too long) 【语法错误,命令无法识别(这可能包括命令行太长等错误)】
504 Command parameter not implemented 【命令参数未实现】
550 Requested action not taken: mailbox unavailable (e.g., mailbox not found, no access, or command rejected for policy reasons)【【请求操作未被执行:邮箱不可用(例如,邮箱未找到,不能访问,或命令拒绝政策原因】】
552 Requested mail action aborted: exceeded storage allocation 【请求的邮件操作中止:超出存储分配】
553 Requested action not taken: mailbox name not allowed (e.g.,mailbox syntax incorrect) 【未执行请求操作:不允许使用邮箱名称(例如,邮箱语法不正确)】
554 Transaction failed (Or, in the case of a connection-opening response, "No SMTP service here") 【事务失败(或者,在连接打开响应的情况下,“这里没有SMTP服务”)】
555 MAIL FROM/RCPT TO parameters not recognized or not implemente【邮件从/RCPT到参数未识别或未实现】