By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,454 Members | 1,804 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,454 IT Pros & Developers. It's quick & easy.

problem with pop3

P: 6
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)

Expand|Select|Wrap|Line Numbers
  1. namespace pop
  2. {
  3.     class Program
  4.     {
  5.         public class pop
  6.         {
  7.              string server = "localhost";
  8.             string user = "honey@localhost";   // dats the user   account in mercury
  9.             string pass = "honey";
  10.             int port = 110;
  11.  
  12.             Socket s = null;
  13.  
  14.            private Socket GetClientSocket()
  15.             {
  16.  
  17.  
  18.                 Socket tempSoc = null;
  19.  
  20.                 try
  21.                 {
  22.  
  23.                     IPHostEntry hostEntry = null;
  24.                     hostEntry = Dns.Resolve(server);
  25.  
  26.  
  27.                     foreach (IPAddress add in hostEntry.AddressList)
  28.                     {
  29.                         IPEndPoint ipe = new IPEndPoint(add, port);
  30.                         tempSoc = new Socket(ipe.AddressFamily,
  31.                            SocketType.Stream, ProtocolType.Tcp);
  32.  
  33.                         tempSoc.Connect(ipe);
  34.  
  35.                         if (tempSoc.Connected)
  36.                         {
  37.                             System.Console.WriteLine("sucsesfull");
  38.                             s = tempSoc;
  39.                             break;
  40.  
  41.                         }
  42.  
  43.                         else
  44.                         {
  45.                             System.Console.WriteLine("not sucsesfull");
  46.                             continue;
  47.                         }
  48.                     }//foreach
  49.                 }
  50.                 catch (Exception e)
  51.                 {
  52.                     System.Console.WriteLine(e.ToString());
  53.                 }
  54.  
  55.             return s;
  56.  
  57.         }//GetClientSocket
  58.  
  59.             private string GetString()
  60.             {           
  61.                 byte[] buffer = new byte[256];
  62.  
  63.                 string line = null;
  64.  
  65.                 try
  66.                 {
  67.                     int byteCount = s.Receive(buffer, buffer.Length, 0);
  68.                     line = Encoding.ASCII.GetString(buffer, 0, byteCount);
  69.                     System.Console.WriteLine("Line" + line);
  70.  
  71.                 }//try
  72.  
  73.                 catch (Exception e) { System.Console.WriteLine("error in GetString()"); }
  74.  
  75.                 return line;
  76.             }//GetString
  77.  
  78.  
  79.             private void send(string user)
  80.             {
  81.                 try
  82.                 {
  83.                     byte[] bytedata = Encoding.ASCII.GetBytes(user + "\r\n");
  84.                     s.Send(bytedata);
  85.                 }//try
  86.  
  87.                 catch (Exception e)
  88.                 {
  89.                     System.Console.WriteLine("Error while sending the username");
  90.                 }
  91.  
  92.             }//send
  93.  
  94.             private void LoginToInbox()
  95.             {
  96.                 System.Console.WriteLine("In LOginToInbox");
  97.                 string returned;
  98.  
  99.                 send("user " + user);
  100.                 returned = GetString();
  101.                 System.Console.WriteLine("user   " + returned);
  102.  
  103.                 if (!returned.Substring(0, 3).Equals("+OK"))
  104.                     System.Console.WriteLine("login not excepted");
  105.  
  106.                 send("pass " + pass);
  107.                 returned = GetString();
  108.                 System.Console.WriteLine("password  " + returned);
  109.  
  110.                 if (!returned.Substring(0, 3).Equals("+OK"))
  111.                     System.Console.WriteLine("login/password not excepted");
  112.  
  113.             }//LoginToInbox
  114.  
  115.             public void OpenInbox()
  116.             {
  117.                 // get a socket ...
  118.                 s = GetClientSocket();
  119.  
  120.                 // get initial header from POP3 server ...
  121.                 string header = GetString();
  122.  
  123.                 System.Console.WriteLine("header" + header);
  124.                 try
  125.                 {
  126.  
  127.                     if (!header.Substring(0, 3).Equals("+OK"))
  128.                     {
  129.                         System.Console.WriteLine("Invalid initial POP3 response");
  130.                     }
  131.  
  132.                     // send login details ...
  133.                     LoginToInbox();
  134.  
  135.                     System.Console.WriteLine("done");
  136.                 }
  137.                 catch (Exception e) { }
  138.             }     
  139.         }//pop3
  140.  
  141.         public static void Main(string[] args)
  142.         {
  143.             pop popC = new pop();
  144.             popC.OpenInbox();
  145.  
  146.             System.Console.Read();
  147.         }
  148.     }
  149. }
Apr 10 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.