25
Apr

Here’s an excellent how-to on using POP3 in your C# apps.  I’ve used it successfully.

The Pop3 class derives from the System.Net namespace:
public class Pop3 : System.Net.Sockets.TcpClient
 
And the class consists of the following fields and methods:
public ArrayList List()
public class Pop3Message
public void Connect(string server, string username, string password)
public void Disconnect()
public Pop3Message Retrieve(Pop3Message rhs)
public void Delete(Pop3Message rhs)
private void Write(string message)
private string Response()
 
Finally, below is a code snippet on how to use the Pop3 class:
static void Main(string[] args)
{
    try
    {
        Pop3 obj = new Pop3();
        obj.Connect("mail.xxx.com", "yyy", "zzz");
        ArrayList list = obj.List();
        foreach (Pop3Message msg in list)
        {
            Pop3Message msg2 = obj.Retrieve(msg);
            System.Console.WriteLine("Message {0}: {1}",
                msg2.number, msg2.message);
        }
        obj.Disconnect();
    }
    catch (Pop3Exception e)
    {
        System.Console.WriteLine(e.ToString());
    }
    catch (System.Exception e)
    {
        System.Console.WriteLine(e.ToString());
    }
}

Nifty ey?  So check out the how-to article.  Enjoy!

Add reply



  • Search:
  • Archives