我正在使用 Exchangelib 库来处理电子邮件。我想在从 Exchange 服务器读取电子邮件时应用过滤器:
@gmail.com
结尾,则排除所有电子邮件。sensitivity=private
)。这是我正在使用的代码片段。 你能帮我们解决过滤器问题吗?
from exchangelib import Credentials, Account , DELEGATE , Q
credentials = Credentials('test@example.com', 'topsecret')
account = Account('john@example.com', credentials=credentials, autodiscover=True, access_type = DELEGATE)
query = Q(sender_contains = '@gmail.com')
recent_mails = account.inbox.filter(~query).order_by('-datetime_received')[:100]
for item in recent_mails:
print(item.subject, item.sender, item.datetime_received)
我也尝试过排除选项:
recent_mails = account.inbox.exclude(query)