title: How do I identify Outlook "message id" over imap/pop3 in Python?
body: <h1>Problem</h1>
  
  <p>I am using a "logic app" in Azure to create a queue of incoming mails. The way the emails are registered are using a "message id", which is described as "a unique identifier for a message". I would like to be able to fetch emails over imap using this id - is this possible?</p>
  
  <h1>Logic app "message id"</h1>
  
  <ol>
  <li>Example of "message id":  </li>
  </ol>
  
  <p>AQMkADAwATM3ZmYAZS0yNTYwLWNkZAAzLTAwAi0wMAoARgAAA-U4TGbG56lEtdoXy_23gW0HAKhWKDtf5AJErHyhh_b9NYQAAAIBDAAAAKhWKDtf5AJErHyhh_b9NYQAAAIFfgAAAA==</p>
  
  <ol start="2">
  <li>Example of logic app:</li>
  </ol>
  
  <p><a href="https://i.stack.imgur.com/j2LRP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j2LRP.png" alt="enter image description here"></a></p>
  
  <h1>What I have tried</h1>
  
  <p>I have tried just to download all emails as eml, and then to read them into notepad++ to see if the "message id" even exists in the eml-files, but they don't.</p>
  
  <pre><code># Library for downloading emails
  import imaplib
  
  # Logging in
  mail = imaplib.IMAP4_SSL("outlook.office365.com",993)
  mail.login(email_user, email_pass)
  
  # Downloading emails to eml
  mail.select('Inbox')
  typ, data = mail.search(None, 'ALL')
  for num in data[0].split():
      typ, data = mail.fetch(num, '(RFC822)')
      f = open('%s/%s.eml' %("/my/path/", num), 'wb')
      f.write(data[0][1])
  mail.close()
  mail.logout()
  </code></pre>