如何在 python 中使用'mark_seen = False'阅读电子邮件后将其标记为看到imap_tools?



首先这是我的代码:

with MailBox('imap.gmail.com').login('username', 'password', 'INBOX') as mailbox:
for msg in mailbox.fetch(AND(mark_seen=False, from_="some_domain")):
prt_msg_text = msg.text
if 'some_text' in prt_msg_text:
*here I want to mark the email as seen, if a specific text is in the msg*

所以我想先阅读电子邮件而不将其标记为已见,如果特定条件为真,我想将此特定电子邮件标记为已见。这可能吗?

mark_seen是fetch的参数。

修复此错误时,请使用mark_seen参数和mailbox。标记方法

我也是新手,但我很擅长谷歌。

from imap_tools import MailBox, A
with MailBox('imap.gmail.com').login('username', 'pwd', 'INBOX') as mailbox:
uids = []
for msg in mailbox.fetch(A(from_="@some.domain"), mark_seen=False):
body = msg.text or msg.html
if 'some_text' in body:
uids.append(msg.uid)
mailbox.flag(uids, imap_tools.MailMessageFlags.SEEN, True)

*mark_seen是fetch参数。

最新更新