hi guys i got this code in c#.net to retrieve mails using pop3 protocal, i'm using MERCURY MAIL SERVER ........
I create a user acccount in mercury by name honey@localhost
the problem is after connecting to the server i get error saying that the password does not match( but the password is correct)
I create a user acccount in mercury by name honey@localhost
the problem is after connecting to the server i get error saying that the password does not match( but the password is correct)
Code:
namespace pop
{
class Program
{
public class pop
{
string server = "localhost";
string user = "honey@localhost"; // dats the user account in mercury
string pass = "honey";
int port = 110;
Socket s = null;
private Socket GetClientSocket()
{
Socket tempSoc = null;
try
{
IPHostEntry hostEntry = null;
hostEntry = Dns.Resolve(server);
foreach (IPAddress add in hostEntry.AddressList)
{
IPEndPoint ipe = new IPEndPoint(add, port);
tempSoc = new Socket(ipe.AddressFamily,
SocketType.Stream, ProtocolType.Tcp);
tempSoc.Connect(ipe);
if (tempSoc.Connected)
{
System.Console.WriteLine("sucsesfull");
s = tempSoc;
break;
}
else
{
System.Console.WriteLine("not sucsesfull");
continue;
}
}//foreach
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
return s;
}//GetClientSocket
private string GetString()
{
byte[] buffer = new byte[256];
string line = null;
try
{
int byteCount = s.Receive(buffer, buffer.Length, 0);
line = Encoding.ASCII.GetString(buffer, 0, byteCount);
System.Console.WriteLine("Line" + line);
}//try
catch (Exception e) { System.Console.WriteLine("error in GetString()"); }
return line;
}//GetString
private void send(string user)
{
try
{
byte[] bytedata = Encoding.ASCII.GetBytes(user + "\r\n");
s.Send(bytedata);
}//try
catch (Exception e)
{
System.Console.WriteLine("Error while sending the username");
}
}//send
private void LoginToInbox()
{
System.Console.WriteLine("In LOginToInbox");
string returned;
send("user " + user);
returned = GetString();
System.Console.WriteLine("user " + returned);
if (!returned.Substring(0, 3).Equals("+OK"))
System.Console.WriteLine("login not excepted");
send("pass " + pass);
returned = GetString();
System.Console.WriteLine("password " + returned);
if (!returned.Substring(0, 3).Equals("+OK"))
System.Console.WriteLine("login/password not excepted");
}//LoginToInbox
public void OpenInbox()
{
// get a socket ...
s = GetClientSocket();
// get initial header from POP3 server ...
string header = GetString();
System.Console.WriteLine("header" + header);
try
{
if (!header.Substring(0, 3).Equals("+OK"))
{
System.Console.WriteLine("Invalid initial POP3 response");
}
// send login details ...
LoginToInbox();
System.Console.WriteLine("done");
}
catch (Exception e) { }
}
}//pop3
public static void Main(string[] args)
{
pop popC = new pop();
popC.OpenInbox();
System.Console.Read();
}
}
}