You seem to be confusing a shell (where you type commands such as telnet
or openssl
) and the socket's protocol.
Using telnet to connect to a port for a protocol like SMTP is a quick hack that allows you to type in directly what you'd normally have to program if implementing a client for that protocol. It can work a little for text-based protocols but it has limitations. In particular, you'll have a hard-time typing an TLS handshake this way: firstly you probably won't be able to find the right keys on your keyboard for some of the bytes you need to send; secondly, you certainly won't be able to read what the server sends you. In short, this approach doesn't make any sense.
openssl s_client -starttls smtp -crlf -connect 127.0.0.1:587
already does what you're trying to do with telnet: it opens the connection to that server, sends the EHLO
SMTP command, sends the STARTTLS
SMTP command and then starts the handshake. The OpenSSL command itself is not part of the SMTP protocol at all and mustn't be sent on the SMTP socket.
What you'll get when running this command should be similar to having your telnet session with the handshake already performed, since you should be able to use its standard input/ouput in the same way you would be able telnet.
This being said, both telnet
and openssl s_client
to send SMTP commands are debugging techniques at best.