I'm using Rebex Components 2012 R2 and I've created a service that will connect to multiple email servers. Each connection to an email server is handled by a seperate thread so we can pull emails at the same time.
I'm getting an error in an unexpect place when I'm downloading from more than one email server at the same time.
I'm able to retrieve the email headers and the actual email without problems. However when I try and write the email to a memory stream, I get the following exception thrown from the line:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at 99RMJ.SWNpk.o6dmZZ(1eAI5d , BinaryWriter )
at 99RMJ.SWNpk.296drUZ(1eAI5d )
at 99RMJ.SWNpk.296drUZ(Stream )
at Rebex.Mail.MailMessage.pKu2tZ(Stream , MailFormat )
at Rebex.Mail.MailMessage.Save(Stream output, MailFormat format)
at Routing.Common.EmailService.EmailConnection.DownloadMessage(ImapMessageInfo message)
Here is basically what I'm doing for each thread/connection:
var messageList = mImapConnection.GetMessageList(ImapMessageSet.All,
ImapListFields.Flags | ImapListFields.UniqueId);
foreach (ImapMessageInfo curMessage in messageList.Where(m => !m.IsDeleted))
MailMessage mailMessage = mImapConnection.GetMailMessage(message.UniqueId);
var mailStream = new MemoryStream();
Note this is ONLY an issue when I'm connected to more than one email server at the same time. I'm creating a seperate instance of Imap for each connection and only have one thread for each connection.