title: build an email database with pywin32
body: <p>I have to iterate through many shared folders within my company. I need to store all the strings of the messages in a database for a machine learning project.
  I read in some threads that I should not iterate through all items using pywin32 and</p>
  <pre><code>messages = mapi.Folders(str(key)).Folders(str(i)).Items
  </code></pre>
  <p>We are talking about 10 shared inboxes with each over 10.000 mails. When i tried to run my code for the first inbox it crashed after reaching 95% (according to tqdm) with this error code</p>
  <blockquote>
  <p>File
  ~.conda\envs\myenv\lib\site-packages\spyder_kernels\py3compat.py:356
  in compat_exec
  exec(code, globals, locals)</p>
  <p>File c:\users\user\desktop\untitled0.py:206 in 
  for m in tqdm(messages):</p>
  <p>File ~.conda\envs\myenv\lib\site-packages\tqdm\std.py:1195 in
  <strong>iter</strong>
  for obj in iterable:</p>
  <p>File
  ~\AppData\Roaming\Python\Python39\site-packages\win32com\client\dynamic.py:324
  in <strong>getitem</strong>
  return self.<em>get_good_object</em>(self.<em>enum</em>.<strong>getitem</strong>(index))</p>
  <p>File
  ~\AppData\Roaming\Python\Python39\site-packages\win32com\client\util.py:41
  in <strong>getitem</strong>
  return self.__GetIndex(index)</p>
  <p>File
  ~\AppData\Roaming\Python\Python39\site-packages\win32com\client\util.py:62
  in __GetIndex
  result = self.<em>oleobj</em>.Next(1)</p>
  <p>com_error: (-459013867, 'OLE error 0xe4a40115', None, None)</p>
  </blockquote>
  <p>I don't understand this error and i can't find anything googling this error. So i thought I should just slice them just in smaller parts and run the code. But I can't slice the messages as I get the error code</p>
  <pre><code>TypeError: Objects of type 'slice' can not be converted to a COM VARIANT
  </code></pre>
  <p>Is there any other way or even a more efficient way to do this task? Should I use instead of pywin32 any other libary? It seems like this is the most proficient libary in this field as it is from microsoft and should have the best compatibility with outlook. But going through 48000 emails of 50000 and then seeing this crash was not planned. How could I save my progress on the way? Can I just sort the messages first and then iterate and therefore commit my retrieved data to an sql database every 5000 emails?</p>