المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Pop3, Smtp, etc..



C# Programming
05-21-2009, 08:50 PM
Hi,

Pop3 and Smtp work the sameway.. one sends a string message to the server (eg: HELO, USER user, PASS pass) and the server responses (eg. 250 Hello and welcome)

Is there any standard class for this type of communication? something simple like
+Connect()
+Write(s)
+LastResponse()

Because i'm not getting good results ..though i'm trying to communicate with gmail's pop and smtp, so maybe i'm failing with the SSL thing..

I'm having trouble with the Writing and Response,

public string SendMessage(string message)
{
ASCIIEncoding asciiEncoder = new ASCIIEncoding();

byte[] WriteBuffer = new byte[1024]; // 1 KB
WriteBuffer = asciiEncoder.GetBytes(message);

NetworkStream stream = cl.GetStream(); // cl is a TcpClient

stream.Write(WriteBuffer, 0, WriteBuffer.Length);

// Get response after message
return Response();
}

And my response method is:

public string Response()
{

byte[] serverbuffer = new Byte[1024]; //1 KB

int count = ns.Read(serverbuffer, 0, 1024);
if (count == 0)
{
return "";
}

return Encoding.ASCII.GetString(serverbuffer, 0, count);


}