Hi,
could you add a BeginListMessages with a bool closetransaction as well? I am trying this code to regularly fetch and delete messages form a Gmail inbox:
private static Pop3Client pop3 = new Pop3Client("pop.gmail.com", 995, @"****", "****");
private static Timer scanTimer;
public static void Main() {
var license = LicenseProvider.GetAsposeLicense();
License emailLicense = new License();
emailLicense.SetLicense(license);
pop3.EnableSsl = true;
scanTimer = new Timer(Pop3Async, null, 0, -1);
Console.Read();
}
static async void Pop3Async(Object o) {
scanTimer.Change(Timeout.Infinite, Timeout.Infinite);
pop3.Quit();
var messages = await Task.Factory.FromAsync(pop3.BeginListMessages(), pop3.EndListMessages);
var count = messages.Count;
Console.WriteLine("new message count: {0}", count);
foreach (var id in messages.Select(m => m.UniqueId)) {
Console.WriteLine("fetching message with id {0}", id);
var message = pop3.FetchMessage(id);
Console.WriteLine("message with subject {0} fetched, deleting", message.Subject);
pop3.DeleteMessage(id);
}
pop3.Quit();
scanTimer.Change(1000, 1000);
}
As per your earlier advice about transaction state, I put Quit() before the asynchronous ListMessages call, and it does recognize new messages that come into the empty inbox after program start. It then fetches and deletes the message, but then after a few ticks of the Timer with 0 new messages, ListMessages strangely returns the id of that message again, and as the message is already deleted, Fetch throws an exception "Wrong Unique ID".
Using var messages = pop3.ListMessages(true); instead of the asynchronous Begin/End call doesn't have this problem, but I really want these calls asynchronous in my application if possible.
Thanks,
Martin