0

我正在使用 Python 中的 imapclient.IMAPClient 处理电子邮件,并希望在最后将成功处理的电子邮件标记为“已看到”。我尝试了不同的方法,但它们要么不会标记所有成功的电子邮件,要么不会在我的 Gmail 收件箱中显示为“已读”。我正在寻找一种方法来更新使用 IMAP 成功处理的电子邮件的 Gmail 收件箱标志。

这是我尝试过的代码摘要:

imapObj = imapclient.IMAPClient(self.server_host, ssl=True)
imapObj.login(self.user_name, self.password)
imapObj.select_folder(email_folder, readonly=False)
#searches unseen emails with subject containing document
self.emails = imapObj.search(
        [search_criterion1, search_value1,
        search_criterion2, search_value2,
        search_criterion3, search_value3,
        search_flag])

#using PEEK to not mark all the emails as [Seen]
self.raw_messages = imapObj.fetch(self.emails, 'BODY.PEEK[]')
self.successful_emails = []
for i, self.email_id in enumerate(self.emails):

...do some process and for each successful process, append the email_id to list...
    self.successful_emails.append(self.email_id)

#flag the successfully processed email as [SEEN] 
imapObj.set_flags(self.successful_emails, '+FLAGS', '\SEEN')
4

0 回答 0