I'm trying to check how many emails have been received from the specified sender.email_address
the past 24 hours, but I get an error from this code
Traceback (most recent call last): File "c:/Users/fmi/Desktop/Python/emailtest.py", line 13, in for item in testfolder.all()
File "C:\Users\fmi\AppData\Local\Programs\Python\Python38-32\lib\site-packages\exchangelib\queryset.py", line 507, in order_by raise ValueError("%s in order_by()" % e.args[0]) ValueError: Unknown field path '-datetime_recieved' on folders [Messages(Root(<exchangelib.account.Account object at 0x020A81F0>, '[self]', 'root', 8, 0, 62, None, 'AQMkADI2YmY4MjAwAC1mNTBkLTQyMzEtYTM0Yi04NTdmZDRhMDE0MGQALgAAA+xnYBMGPANEmpY/yEHuM6wBAEYSp+OGVQhHl3U8WgJ/ZQAAAwEBAAAAAA==', 'AQAAABYAAABGEqfjhlUIR5d1PFoCf2UAAAAcRKyn'), 'Test', 26821, 26654, 0, 'IPF.Note', 'AQMkADI2YmY4MjAwAC1mNTBkLTQyMzEtYTM0Yi04NTdmZDRhMDE0MGQALgAAA+xnYBMGPANEmpY/yEHuM6wBAEYSp+OGVQhHl3U8WgJ/ZQAAAw0rAAAA', 'AQAAABYAAABGEqfjhlUIR5d1PFoCf2UAAAAcRKxr')] in order_by()
when trying to print. I also want it to give me an alert if the email count is 0.
from exchangelib import Credentials, Account, UTC_NOW
from collections import defaultdict
from datetime import timedelta
credentials = Credentials('fmi@.dk', 'something')
a = Account('fmi@.dk', credentials=credentials, autodiscover=True)
counts = defaultdict(int)
testfolder = a.inbox.parent / 'Test'
since = UTC_NOW() - timedelta(hours=24)
for item in testfolder.all()\
.only('sender', 'subject')\
.filter(datetime_received__gt=since)\
.order_by('-datetime_received'):
if item.sender.email_address == 'info@something.dk':
counts[item.sender.email_address, item.subject] += 1
print(counts)