Error Retreiving MessageObject with Imap Library

Jun 20, 2012 at 3:54 PM


The Following code below gives me the following errors,
A first chance exception of type 'System.IndexOutOfRangeException' occurred in ActiveUp.Net.Imap4.dll
A first chance exception of type 'ActiveUp.Net.Mail.Imap4Exception' occurred in ActiveUp.Net.Imap4.dll
ActiveUp.Net.Mail.Imap4Exception: Command "fetch 1 body[mime]" failed : 120620095014100 BAD Could not parse command

when trying to do this, if i Comment out the msg = Line then i don't get any errors, it will tell me how many messages are in the mailbox etc but will not retreive the messages.

if (inbox.MessageCount > 0)
                    for (int i = 1; i < inbox.MessageCount + 1; i++)
                            ActiveUp.Net.Mail.Message msg;
                            msg = inbox.Fetch.MessageObjectPeek(1);
                        catch (Exception err)


Any help would be greatly appreciated.




Jun 20, 2012 at 3:55 PM

Oh another thing to note is that i've tried using our internal IMap server which is what i'm looking to use in the end but i've also tried with GMail's server as well to rule out configuration issues with our server.

Dec 21, 2012 at 5:48 PM



I'm currently having the same problem. Did you ever find a solution?

My guess is that this depends on the server's capabilities. At least depending on it's capabilities the peek method sends a different command. I'm trying this with the gmail server. The server tells that it capable of IMAP4rev1. 

I found also a defect that seem to match this:

Unfortunately I'm not, yet, able to build the libs newly. Maybe a just duplicate the code locally to try it out. 

Did you find a solution that you may share?

Best regards,

Dec 21, 2012 at 6:33 PM

Hi again!

I don't whether this is still interessting for you - I guess no considering the date when you posted your question. Anyway, maybe someone else will find this in future.

So, here's the solution: 

In file fetch.cs, line #1412 it has to be changed


response = this.ParentMailbox.SourceClient.Command( "fetch " + messageOrdinal.ToString( ) + " body[mime]", getFetchOptions( ) );


response = this.ParentMailbox.SourceClient.Command( "fetch " + messageOrdinal.ToString( ) + " body.peek[]", getFetchOptions( ) );

I built a new lib and it works as expected and w/o throwing exceptions.

Best regards,

Apr 8, 2013 at 1:15 PM
I have a problem when to fetch email after Login.

My account type is IMAP and my account test is gmail.

I Have a exception "Object reference not set to an instance of an object." in this Section
 public BindingList<MailMessage> RetrieveMessages(string mailbox, int beginIndex, int increment)
            BindingList<MailMessage> ret = new BindingList<MailMessage>();

            MailMessage mailMessage;
            Header header;

            Mailbox inbox = this._imap4Client.SelectMailbox(mailbox);
            Fetch fetch = inbox.Fetch;
            int messageCount = inbox.MessageCount;
            for (int i = beginIndex; i <= beginIndex + increment; i++)
                if (i <= messageCount)
                    header = fetch.HeaderObject(i);
                    mailMessage = new MailMessage();
                    mailMessage.BaseIndex = i;
            return ret;
Specially in Line
 header = fetch.HeaderObject(i);
can anyone solve this problem?