0

Problem

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?

Logic app "message id"

  1. Example of "message id":

AQMkADAwATM3ZmYAZS0yNTYwLWNkZAAzLTAwAi0wMAoARgAAA-U4TGbG56lEtdoXy_23gW0HAKhWKDtf5AJErHyhh_b9NYQAAAIBDAAAAKhWKDtf5AJErHyhh_b9NYQAAAIFfgAAAA==

  1. Example of logic app:

enter image description here

What I have tried

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.

# 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()
Esben Eickhardt
  • 3,183
  • 2
  • 35
  • 56

1 Answers1

1

May i know why are you trying to fetch email over IMAP . As you can fetch fetch email using message id from outlook api too. Here is the api which you can use:

GET https://outlook.office.com/api/v2.0/me/messages/{message_id}

You can find more details here:

https://learn.microsoft.com/en-us/previous-versions/office/office-365-api/api/version-2.0/mail-rest-operations#GetMessages

Also just to update , in outlook you wont' find the message id in .eml or in body, it's available in internet header. Most clients utilities download the headers (including the Message-ID) of all messages, store them, and then post-process them. For outlook you can find it in internet header like below:

enter image description here

enter image description here

Reference: https://www.codetwo.com/kb/messageid/

Still if you want to access email using IMAP, try below thread and see if it helps:

https://www.go4expert.com/articles/accessing-email-using-imap-python-t28838/

https://social.msdn.microsoft.com/Forums/en-US/29f44441-feda-4f81-a04c-40d53b3dfdc5/how-to-access-an-email-using-messageid-in-outlook?forum=outlookdev

Hope it helps.

Mohit Verma
  • 5,140
  • 2
  • 12
  • 27
  • This "message-id" doesn't look like a Message-Id header mesasge-id (which is supposed to look like xyz@domain.com – Max Sep 19 '19 at 14:34
  • I have tried to use the outlook api, but I think the documentation is pretty horrible. It does not state how I make an "app registration" just for one outlook account - also it states that you can use it for personal accounts, but when I try to do that it requires that the email account is part of an organizations AD. – Esben Eickhardt Sep 30 '19 at 10:34