'Search Email Of Last N Minutes Using IMAP-TOOLS
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
