Hi Siraj,
Below is the sample code snippet of a program that
- checks the inbox of pop3 mail server
- downloads all the emails
- delete the email (based on a condition)
Pop3Client client = null;
try
{
Console.WriteLine(“Connecting to pop3…”);
client = new Pop3Client(“host”, 110, “
user@host.com
”, “pwd”);
client.Connect(true);
Console.WriteLine(“Connected to pop3.”);
if (client.GetMessageCount() > 0)
{
Console.WriteLine(“Checking messages…”);
Pop3MessageInfoCollection msgInfoColl = client.ListMessages();
// check all messages in inbox
foreach (Pop3MessageInfo msgInfo in msgInfoColl)
{
MailMessage msg = client.FetchMessage(msgInfo.SequenceNumber);
Console.WriteLine(“Subject: " + msg.Subject);
foreach (Attachment att in msg.Attachments)
{
Console.WriteLine(“Attachment Name: " + att.Name);
}
// delete message according to a condition
if (msgInfo.Subject == “some special words”)
{
client.DeleteMessage(msgInfo.SequenceNumber);
Console.WriteLine(”===========This message is deleted============”);
}
Console.WriteLine("===============================");
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
client.Disconnect();
Console.WriteLine(“Disconnected.”);
}