When using telnet or netcat to test an outgoing SMTP email I cannot end message 'with "." on a line by itself'
When sending a simple email via telnet or netcat to my ISP's SMTP server I cannot terminate the message with a period. Eventually the connection times out but the message is not delivered.
root@zeus:/tmp# telnet mail.charter.net 25
220 imp09 smtp.charter.net ESMTP server ready 20110115 000442
HELO charter.net
250 imp09 hello [97.94.115.109], pleased to meet you
MAIL FROM: test@gmail.com
250 2.1.0 <test@gmail.com> sender ok
RCPT TO: test@gmail.com
250 2.1.5 <test@gmail.com> recipient ok
DATA
354 enter mail开发者_运维知识库, end with "." on a line by itself
test body
.
.
/n.
/n
.
\n
.
QUIT
This works fine on another computer on the same network and ISP with a different version of telnet.
netcat hangs the same way on both computers.
I was thinking this may have something to do with LINEMODE, as the telnet session that cannot send the email is in LINEMODE and cannot switch to CHARMODE. Are there any work arounds?
The newlines you are sending are probably just a carriage return or just a linefeed character. SMTP requires a carriage return followed by a line feed to end a line.
https://www.rfc-editor.org/rfc/rfc5321#section-2.3.8
https://www.rfc-editor.org/rfc/rfc5321#section-4.1.1.4
Try ending each line with Control-M Control-J, using a different terminal program, and/or using something other than telnet.
A shot in the dark, but maybe try pressing CTRL-J instead of Enter after typing the .
.
To see what's really going on you can use one of these tools:
strace
records all system calls, including everything you write or read to files or the network. You can examine the output of that program to see if the lines are properly terminated by\r\n
.wireshark
records and displays network traffic. Use it to record the traffic, filter ontcp.port==25
and then Follow TCP stream to see which bytes have really been sent over the wire.
As stated above, the SMTP protocol requires CRLF characters to properly recongise the end of a message.
If using telnet (or openssh on secure connections) from a Linux/MacOS base, you must tell that program to use the correct style of line endings, by using the -crlf option.
e.g. telnet -crlf mail.charter.net 25
精彩评论