Now i'm just getting all the messages in a backgroundworker dowork event:
private int numberofallmessages = 0; private int countMsg = 0;
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
List<string> uids = new List<string>();
using (var client = new Pop3Client())
{
client.Connect(textServer.Text, Convert.ToInt32(textPort.Text), ssl);
client.AuthenticationMechanisms.Remove("XOAUTH2");
client.Authenticate(textUser.Text, textPassword.Text);
for (int i = client.Count -1; i > 0; i--)
{
if (backgroundWorker1.CancellationPending == true)
{
e.Cancel = true;
return;
}
if (i > 0)
{
allMessages.Add(client.GetMessage(i));
}
int nProgress = (client.Count - i + 1) * 100 / client.Count;
backgroundWorker1.ReportProgress(nProgress, client.Count.ToString() + "/" + i);
}
client.Disconnect(true);
}
}
I'm getting all the messages about 6000. Now i want to have in a button click event a code so each time i click on the button it will check for a new email. Same idea like in outlook for example.
And also maybe to use an event that will automatic give a notice when a new emails arraived.
I saw this code example:
MailKit E_MailKit_MailFolder_CountChanged
But first i'm not sure if this is what i need/want in my case and second in the example they are using imap but in my code i'm using pop3 and also my account i'm using in the backgroundworker in the Authenticate is a pop3 account.
I want that once after i got all messages like 6000 from now on when clicking the button it will check/get only new emails and not all over again the 6000 emails.