title: How to check all emails that came in within a time period?
body: <p>I have the following method <code>get_email()</code> that basically every 20 seconds, gets the latest email and performs a series of other methods on it.</p>
  
  <pre><code>def get_email():
      import win32com.client
      import os
      import time
      import datetime as dt
  
      date_time = time.strftime('%m-%d-%Y')
  
      outlook = win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
      inbox = outlook.GetDefaultFolder(6)
  
      messages = inbox.Items
      message = messages.GetFirst()  # any time calling GetFirst(), you can get GetNext()....
      email_subject = message.subject
      email_sender = message.SenderEmailAddress
      attachments = message.Attachments
      body_content = message.body
  
      print ('From: ' + email_sender)
      print ('Subject: ' + email_subject)
  
      if attachments.Count &gt; 0:
          print (str(attachments.Count) + ' attachments found.')
          for i in range(attachments.Count):
                  email_attachment = attachments.Item(i+1)
                  report_name = date_time + '_' + email_attachment.FileName
                  print('Pushing attachment - ' + report_name + ' - to check_correct_email() function.')
  
                  if check_correct_email(email_attachment, email_subject, report_name) == True:
                      save_incoming_report(email_attachment, report_name, get_report_directory(email_subject))
                  else:
                      print('Not the attachment we are looking for.')
                      # add error logging here
                      break
  
      else: #***********add error logging here**************
          print('No attachment found.')
  </code></pre>
  
  <p>My main question is:</p>
  
  <ul>
  <li>Is there a way I can iterate over every email using the <code>GetNext()</code> function per se every hour instead of getting the latest one every 20 seconds (which is definitely not as efficient as searching through all emails)?</li>
  </ul>
  
  <p>Given that there are two functions: <code>GetFirst()</code> and <code>GetNext()</code> how would I properly have it save the latest checked, and then go through all the ones that have yet to be checked? </p>
  
  <hr>
  
  <p>Do you think it would be easier to potentially set up a different folder in Outlook where I can push all of these reports to, and then iterate through them on a time basis? The only problem here is, if an incoming report is auto-generated and the time interval between the email is less than 20 seconds, or even 1 second.</p>
  
  <hr>
  
  <p>Any help at all is appreciated! </p>