title: Fetching all mails in Inbox from Exchange Web Services Managed API and storing them as a .eml files
body: <p>I want to fetch all mails in the Inbox folder using EWS Managed API and store them as <code>.eml</code>. The problem is in fetching <strong>(1) all</strong> mails with <strong>(2) all headers (like from, to, subject)</strong> (I am keeping information of those values of <code>from</code>, <code>to</code> and other properties somewhere else, so I need them too) and <strong><code>(3)byte[] EmailMessage.MimeContent.Content</code></strong>. Actually I am lacking understanding of  </p>
  
  <ul>
  <li><code>Microsoft.Exchange.WebServices.Data.ItemView</code>,</li>
  <li><code>Microsoft.Exchange.WebServices.Data.BasePropertySet</code> and </li>
  <li><code>Microsoft.Exchange.WebServices.Data.ItemSchema</code></li>
  </ul>
  
  <p>thats why I am finding it difficult.</p>
  
  <p>My primary code is:</p>
  
  <p>When I create <code>PropertySet</code> as follows:</p>
  
  <pre><code>PropertySet properties = new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.MimeContent);
  </code></pre>
  
  <p>I get following exception:</p>
  
  <pre><code>The property MimeContent can't be used in FindItem requests.
  </code></pre>
  
  <p>I dont understand </p>
  
  <p><strong>(1)</strong> What these <code>ItemSchema</code> and <code>BasePropertySet</code> are</p>
  
  <p><strong>(2)</strong> And how we are supposed to use them</p>
  
  <p>So I removed <code>ItemSchema.MimeContent</code>:</p>
  
  <pre><code>PropertySet properties = new PropertySet(BasePropertySet.FirstClassProperties);
  </code></pre>
  
  <p>I wrote simple following code to get all mails in inbox:</p>
  
  <pre><code>ItemView view = new ItemView(50);
  view.PropertySet = properties;
  FindItemsResults&lt;Item&gt; findResults; 
  List&lt;EmailMessage&gt; emails = new List&lt;EmailMessage&gt;();
  
  do
  {    
      findResults = service.FindItems(WellKnownFolderName.Inbox, view);
      foreach (var item in findResults.Items)
      {
          emails.Add((EmailMessage)item);
      }
      Console.WriteLine("Loop");
      view.Offset = 50;
  }
  while (findResults.MoreAvailable);
  </code></pre>
  
  <p>Above I kept page size of <code>ItemView</code> to 50, to retrieve no more than 50 mails at a time, and then offsetting it by 50 to get next 50 mails if there are any. However it goes in infinite loop and continuously prints <code>Loop</code> on console. So I must be understanding <code>pagesize</code> and <code>offset</code> wrong. I want to understand </p>
  
  <p><strong>(3)</strong> what <code>pagesize</code>, <code>offset</code> and <code>offsetbasepoint</code> in <code>ItemView</code> constructor means</p>
  
  <p><strong>(4)</strong> how they behave and</p>
  
  <p><strong>(5)</strong> how to use them to retrieve all mails in the inbox</p>
  
  <p>I didnt found any article online nicely explaining these but just giving code samples. Will appreciate question-wise explanation despite it may turn long. </p>