In fact, this way is to read the data stream all into a string form, but the actual network transmission, the SMTP server is not all the return of the valid command, the command is in <CRLF> (carriage return add line) end. Therefore, there is a problem with this way of reading.
This allows you to intercept a command that ends with a carriage return. However, this is not correct, because the SMTP server in some cases will send back some of the welcome information and so on, they are also in the <CRLF> (carriage return add line) ended, we use the above program is probably not what we actually want to get the correct command.
So I only have to revise the procedure as follows:
/**
*
* Read the server's return stream
*
*/
public string Readfromnetstream (ref NetworkStream NetStream)
{
/**
*
* Read the server's return information on a line-by-row basis
*
*/
Public byte[] ReadLine (NetworkStream m_strmsource)
{
ArrayList linebuf = new ArrayList ();
byte prevbyte = 0;
int currbyteint = M_strmsource.readbyte ();
while (Currbyteint >-1)
{
Linebuf.add ((byte) currbyteint);
if ((Prevbyte = (byte) ' \ R ' && (byte) Currbyteint = = (byte) ')
{
byte[] RetVal = new Byte[linebuf.count-2];
Linebuf.copyto (0,retval,0,linebuf.count-2);
return retVal;
}
Prevbyte = (byte) currbyteint;
Currbyteint = M_strmsource.readbyte ();
}
if (Linebuf.count > 0)
{
byte[] RetVal = new Byte[linebuf.count];
Linebuf.copyto (0,retval,0,linebuf.count);
return retVal;
}
return null;
}
/**
*
* Convert server's return information line to string
*
*/
public string Readlinestr (NetworkStream mystream)
{
Byte[] B = readLine (MyStream);
if (null = = b)
{
return null;
}
Else
{
return System.Text.Encoding.ASCII.GetString (b);
}
}
As a result, we can read those data streams that start with a 3-bit response code, add a space, and then some send back, ending in the correct command format for carriage return plus line wrapping.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.