// We instantiate the pop3 client

Pop3Client pop = new Pop3Client();

 

try

{

    this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server));

 

    // We connect to the pop3 client

    pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);

 

    if (pop.MessageCount > 0)

    {

        // We retrive a message at a particulat index

        ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1);

 

        // We verify if the message is from black listed server

        foreach (string blackServer in _lvBlackListServers.Items)

        {

            if (message.From.Email.EndsWith(bServer))

            {

                this.AddLogEntry(string.Format("Messages from {0} are not allowed", blackServer));

                break;

            }

        }

    }

 

    else

    {

        this.AddLogEntry("There is no messages in the pop3 account.");

    }

}

 

catch (Pop3Exception pexp)

{

    this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));

}

 

catch (Exception ex)

{

    this.AddLogEntry(string.Format("Failed: {0}", ex.Message));

}

 

finally

{

    if (pop.IsConnected)

    {

        pop.Disconnect();

    }

}