Pop3 asynchronous Fetch doesn't work with multiple clients

Hi,

I’m trying to use parallelism to download and process multiple email messages from the same account at the same time using multiple Pop3Client instances, this approach has worked for ImapClient. I wasn’t sure as Pop3 is not supposed to support multiple connections, but I wanted to try it.

This snippet is synchronous and obviously serialized and works fine:

static void MultiFetchPop3(Object o)

{

var client1 = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, 995, @“xxxx@gmail.com”, “xxxx”);

client1.EnableSsl = true;

client1.Connect();

var client2 = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, 995, @“xxxx@gmail.com”, “xxxx”);

client2.EnableSsl = true;

client2.Connect();

var fetch1 = client1.FetchMessage(1);

var fetch2 = client2.FetchMessage(2);

Console.WriteLine(“Fetched 1st message, subject: {0}”, fetch1.Subject);

Console.WriteLine(“Fetched 2nd message, subject: {0}”, fetch2.Subject);

client1.Disconnect();

client2.Disconnect();

Console.WriteLine(“sync all done!”);

}

This snippet is asynchronous and thus runs in parallel:

static async void MultiFetchPop3Async(Object o)

{

var client1 = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, 995, @“xxxx@gmail.com”, “xxxx”);

client1.EnableSsl = true;

client1.Connect();

var client2 = new Pop3Client(“[pop.gmail.com](http://pop.gmail.com/)”, 995, @“xxxx@gmail.com”, “xxxx”);

client2.EnableSsl = true;

client2.Connect();

var fetch1 = Task.Factory.FromAsync(client1.BeginFetchMessage, client1.EndFetchMessage, 1, null);

var fetch2 = Task.Factory.FromAsync(client1.BeginFetchMessage, client1.EndFetchMessage, 2, null);

await Task.WhenAll(fetch1, fetch2);

Console.WriteLine(“Fetched 1st message, subject: {0}”, fetch1.Result.Subject);

Console.WriteLine(“Fetched 2nd message, subject: {0}”, fetch2.Result.Subject);

client1.Disconnect();

client2.Disconnect();

Console.WriteLine(“async all done!”);

}

The code doesn’t crash (as opposed to trying to run botch async fetches from the same client which throws a not supported exception) but it returns the 1st message for both fetches, the subject in both WriteLines will be the subject of the 1st message. Interestingly though, when I check the email account (I have gmail set to delete email picked up by Pop3) both 1st and 2nd messages are deleted, so the 2nd message was indeed accessed, just not returned. This is a bit strange… Is it a limitation of Pop3 or is it something that could be fixed on Aspose side?

Thank you,

Martin

Hi Martin,


We are sorry for a delayed response.

I have tested this scenario at my end using the latest version of Aspose.Email for .NET 3.8.0 and could observe the issue as stated. I would like to share that we are already in process of improving the asynchronous functionality of Aspose.Email’s Pop3Client via issue id: NETWORKNET-34245. This issue has been linked with the logged ticket and once there is a fix version available in this regard, we’ll update you here.

We regret the inconvenience caused to you in this regard.

Shame on me, I have just checked this thread for news and noticed I had an error in my code, if you notice both async fetch calls they’re both done from client1. Client2 is not used. I have tested this again with 2 clients with Aspose.Email 3.9.0 with both sequence number and Id and it works as expected.


Martin

Hi Martin,


It is nice to know that your problem is identified and resolved now. Please feel free to write us back if you have any other query related to Aspose.Email.