The following code uses IMAP to log into an Outlook email and checks the contents of the Junk folder.
It returns the content of the last unseen email with subject "Title".
I would like to add one thing to the source code.
Is it possible to get the last email of for example the last 10 minutes? So that he doesn't return older emails.
from imap_tools import MailBox, AND
with MailBox('imap.outlook.com').login(email, password, 'Junk') as mailbox:
for msg in mailbox.fetch(AND(subject = f'title', seen = False), limit = 1, reverse = True):
body = msg.text
for line in body.splitlines():
print(line)