I tried to use exchangelib to extract group mailbox for analysis, and i want to extract within a date range.
tried to use Filter function but seems only work for calender, may I have your advise is there any sample for email ?
thanks all.
You need to filter on a datetime field that is available on Message items. Message.FIELDS
contains all available fields on the Message
class. You can list all datetime fields with something like:
>>> [f.name for f in Message.FIELDS if f.value_cls == EWSDateTime]
['datetime_received', 'datetime_sent', 'datetime_created', 'reminder_due_by', 'last_modified_time']
The README shows examples using .filter(start__range(x, y))
, but the start
field is only available on CalendarItem
objects. Instead, use e.g. datetime_received
to filter Message
objects:
tz = EWSTimeZone.localzone()
emails_from_2017 = account.inbox.filter(datetime_received__range=(
tz.localize(EWSDateTime(2017, 1, 1)),
tz.localize(EWSDateTime(2018, 1, 1))
))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With