It is a simple package for TcpClient. My biggest problem while programming was that NetworkStream has no Length. My solution is to parse server response and then decide whether to get more response (some advise please).
The code makes a TextBox like a console, as follows:
tbConsole.SelectionStart tells us where the current cursor is. In order to limit the actions of the TextBox, I changed the manner of arrow keys, enter key, and backspace. There are several special commands: the style "$string" means convert "string" to base64 string, then send "@filename" means load "filename" from disk, and send to server ".string" means send "string" to server but don't try to get response. That's the main difference from command line tool Telnet.
The common command sequence to communicate with a SMTP server should be as follows:
HELO dear server
AUTH LOGIN
(enter base64 string as username)
(enter base64 string as password)
MAIL From:sa@mail.local
RCPT To:target@mail.local
DATA
(send mail data to server)
.(send over)
QUIT
HELO is some level equivalent to EHLO (without detailed command prompt). So in my console, just enter the following commands to send a mail:
HELO dear server
AUTH Login
$myname
$mypass
MAIL From:sa@mail.local
RCPT To:test@mail.local
DATA
@c:\mail.txt
.
QUIT
Here is a sample mail:
From: from@mail.local
To: to@mail.local
Subject: hello boy
nice to meet you
Make some changes, you can turn this console into any kind of TCP client. So that's all.