0

Sorry If the title sounds confusing I will try my best to explain here, I m trying to scan new emails from the provided timestamp without using DateTime.DateTime.now()

for example my provided timestamp is date1 = "2022-02-05 04:03:17.690370+00:00

I want to run code for all the emails that came after this timestamp till the latest something like operator.. greater than date1.

I can use datetime_received_range=(date1, date2 ##date2 being datetime.now()) but I want to use another method.

date1 = datetime.datetime(2022, 2, 4, 20, 53, 15, tzinfo=tzutc()) ##example stored timestamp
date2 = datetime.datetime(2022, 2, 5, 4, 3, 17, 690370, tzinfo=tzutc()) ##example current timestamp

query = Q(subject='Media_Core Process')
recent_emails = account.inbox.filter(~query, datetime_received__range=(
    date1,
    date2
))

for item in recent_emails:  
    print(item.subject, item.sender, item.datetime_received)

  • When you post your question multiple places, it's good form to connect them so people can find the answer regardless of how they find your question. I've also left an answer in your issue at https://github.com/ecederstrand/exchangelib/issues/1044 – Erik Cederstrand Feb 05 '22 at 15:43
  • Thank you, This is my first project and I m focusing more on learning than just completing, so instead of asking my seniors I preferred to do some research and ask community for help. –  Feb 05 '22 at 19:08

1 Answers1

0

If you want to do a greater-than filter, use __gt or __gte (> and >=, respectively) instead of __range.

Erik Cederstrand
  • 9,643
  • 8
  • 39
  • 63
  • Thank you !! I was trying datetime_received > timestamp all the time and I was getting error using __gte fixed it. –  Feb 05 '22 at 19:10