[英]Imap_tools Multiple NOT Conditions
I am using imap_tools to access and process our business emails.我正在使用 imap_tools 访问和处理我们的业务电子邮件。 I would like to filter out multiple different
from_
messages.我想过滤掉多个不同
from_
消息。
Here's working code for filtering out one from_
address.这是用于过滤出一个
from_
地址的工作代码。 This returns all emails within the date range except those from notifications@stripe.com
这将返回日期范围内的所有电子邮件,但来自
notifications@stripe.com
的电子邮件除外
from imap_tools import MailBox, A, AND, OR, NOT
import datetime as dt
from bs4 import BeautifulSoup
username = "info@mysite.co.uk"
password = "mypasword"
imap_server = "mysite.co.uk"
# Get date, subject and body len of all emails from INBOX folder
with MailBox(imap_server).login(username, password) as mailbox:
for msg in mailbox.fetch(
AND(NOT(from_="notifications@stripe.com"), date=dt.date(2022, 9, 9))
):
# print(msg.date, msg.subject, msg.html)
if msg.html:
soup = BeautifulSoup(msg.html, "html.parser")
print(msg.from_)
print(msg.subject)
print(msg.date)
print(soup.prettify)
print(180 * "=")
This is what I have tried:这是我尝试过的:
# Get date, subject and body len of all emails from INBOX folder
with MailBox(imap_server).login(username, password) as mailbox:
for msg in mailbox.fetch(
AND(
NOT(from_=["notifications@stripe.com", "noreply@wise.com"]),
date=dt.date(2022, 9, 9),
)
):
As per the docs one should pass in a list of str.根据文档,应该传入一个 str 列表。
from_: str | List[str] | None = None
But when I try and pass in a list of email addresses that I don't want to fetch, it just returns all the emails within the date range.但是,当我尝试传入我不想获取的 email 地址列表时,它只会返回日期范围内的所有电子邮件。
Any ideas?有任何想法吗? Thanks in advance!
提前致谢!
Seems it is limitation of your server.似乎这是您服务器的限制。
I have checked on YANDEX - the same.我已经检查过 YANDEX - 一样。
On another server it works.在另一台服务器上它可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.