// We instantiate the pop3 client.
Pop3Client pop = new Pop3Client();
try
{
_lvMessages.Items.Clear();
this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server.Text));
// Connect to the pop3 client
pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);
if (pop.MessageCount > 0)
{
//Retrive a messaheader at a particulat index (index 1 in this sample)
for (int i = 1 ; i < pop.MessageCount + 1; i++)
{
ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(i);
ListViewItem lvi = new ListViewItem();
lvi.Text = i.ToString("0000");
lvi.SubItems.AddRange(new string[] { message.Subject });
lvi.Tag = message;
_lvMessages.Items.Add(lvi);
this.AddLogEntry(string.Format("{3} Subject: {0} From :{1} Message Body {2}"
, message.Subject, message.From.Email, message.BodyText,i.ToString("0000")));
break;
}
}
else
{
this.AddLogEntry("There is no message in this 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();
}
}