Python、IMAP 和 GMail.将消息标记为已查看 [英] Python, IMAP and GMail. Mark messages as SEEN

查看:25
本文介绍了Python、IMAP 和 GMail.将消息标记为已查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 python 脚本,它必须获取看不见的消息,对其进行处理,并将其标记为已见(或已读)

I have a python script that has to fetch unseen messages, process it, and mark as seen (or read)

我在登录后这样做:

    typ, data = self.server.imap_server.search(None, '(UNSEEN)')

    for num in data[0].split():
        print "Mensage " + str(num) + " mark"
        self.server.imap_server.store(num, '+FLAGS', '(SEEN)')

第一个问题是,搜索返回所有消息,而不仅仅是 UNSEEN.第二个问题是邮件没有标记为 SEEN.

The first problem is that, the search returns ALL messages, and not only the UNSEEN. The second problem is that messages are not marked as SEEN.

谁能帮帮我?

谢谢!

推荐答案

import imaplib
obj = imaplib.IMAP4_SSL('imap.gmail.com', '993')
obj.login('user', 'password')
obj.select('Inbox')   <--- it will select inbox
typ ,data = obj.search(None,'UnSeen')
obj.store(data[0].replace(' ',','),'+FLAGS','Seen')

这篇关于Python、IMAP 和 GMail.将消息标记为已查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆