title: MailSystem.Net Delete Message, IndexOnServer Property = 0
body: <p>I'm using <a href="http://mailsystem.codeplex.com" rel="nofollow noreferrer">MailSystem.NET</a> and trying to delete a message from the server. The problem is the IndexOnServer property is 0, and I get the following error:</p>
  <pre><code>Command &quot;store 0 +flags.silent (\Deleted)&quot; failed : 121031084812790 BAD Error in IMAP command STORE: Invalid messageset
  </code></pre>
  <p>Here's my code:</p>
  <pre><code>    Imap4Client client = new Imap4Client();
      client.Connect(account.Server, account.Username, account.Password);
      var inbox = client.SelectMailbox(&quot;Inbox&quot;);
      MessageCollection messages = inbox.SearchParse(&quot;SINCE &quot; + DateTime.Now.AddHours(-hours).ToString(&quot;dd-MMM-yyyy&quot;));
  
      foreach (Message newMessage in messages)
      {
          inbox.DeleteMessage(newMessage.IndexOnServer, true);
      }
  </code></pre>
  <p>How do I get the correct index of the message so I can delete it?</p>
  <hr>
  <p><b>Edit:</b></p>
  <p>The problem with the suggestions using the standard 1-based loop is that the counter index won't be in sync with the message index, since in my case I'm searching to retrieve a specific subset of messages only (as I understand it).</p>
  <p>Thank you.</p>