一 背景
探测163的发件服务器smtp.163.com,对于流程中的data命令总是报500 bad syntax 错误,后找资料发现,data有格式要求,“end with <CRLF>.<CRLF> ”, 但尝试 “data \r\n.\r\n” 仍然失败。
二 telnet流程
代码未走通,先通过telnet尝试,流程如下:
220 163.com Anti-spam GT for Coremail System (163com[20141201])
HELO 163.COM
250 OK
AUTH LOGIN
334 dXNlcm5hbWU6
xxxxxxxxxxxxxxxx // 163邮箱账号的base64编码
334 UGFzc3dvcmQ6
xxxxxxxxxxxxxxxx // 账户密码的base64编码
235 Authentication successful
MAIL FROM :<xxxxxx@163.com> // 发件人邮箱账户
250 Mail OK
rcpt to : <xxxxxxxxxxx@163.com> // 收件人邮箱账户
250 Mail OK
data
354 End data with <CR><LF>.<CR><LF>
SUBJECT: hahahahahahah // 发送邮件主题
. // 邮件编辑结束符
250 Mail OK queued as smtp12,EMCowACnrlbF94RblO5eDg--.15992S3 1535441150
发现data命令直接回车后能够正确返回354.
于是将代码改为“data\r\n” ,通过。
三 RFC5321说明
查看rfc5321中data命令的相关说明:
……
The mail data are terminated by a line containing only a period, thatis, the character sequence "<CRLF>.<CRLF>", where the first <CRLF> isactually the terminator of the previous line (see Section 4.5.2).This is the end of mail data indication. The first <CRLF> of this terminating sequence is also the <CRLF> that ends the final line ofthe data (message text) or, if there was no mail data, ends the DATAcommand itself (the "no mail data" case does not conform to this specification since it would require that neither the trace header fields required by this specification nor the message header section required by RFC 5322 [4] be transmitted).
……
也就是说data命令在"no mail data"场景下,并不需要遵循<CRLF>.<CRLF>的结束格式。