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