简体   繁体   中英

How do I filter inbox and only download emails that have attachments

I am filtering a fairly large inbox using exchangelib. I only want to look at emails that have attachments.

I tried to add the attachments=True clause in the filter but it does not work. Below is my code. Could someone tell me what is the correct way of doing this?

account.inbox.filter(datetime_received__range=(start_time, end_time), sender=some_sender, attachments=True)

You probably want to filter on the has_attachments filter instead. I don't think you can filter directly on an attachment. Also, you may want to only select the fields that you need, using .only() :

account.inbox.filter(
    datetime_received__range=(start_time, end_time),
    sender=some_sender,
    has_attachments=True,
).only('sender', 'subject', 'attachments')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM