I want to receive all the today's email texts from a specific sender and put them into a list from outlook with imap-tools
I have made the following function but the problem is that it doesn't retrieve emails from 12:00AM - 12:00PM, is there any way to specify the hours for getting the proper messages?
def get_emails(username, password, sender):
from imap_tools import MailBox, A
emails = []
with MailBox('outlook.office365.com').login(username, password, 'INBOX') as mailbox:
for msg in mailbox.fetch(
A(
A(date_gte=datetime.date.today()), # get the today's emails
A(from_=sender), # from the specific senderEmailAddress
),
mark_seen = True
):
if msg.subject == "Subject":
emails.append(msg.text)
return emails